From ea814fcb37f3d84f6a6836e420991152f9b6dc99 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Tue, 27 Jun 2023 17:22:35 +0200 Subject: [PATCH 1/2] fix: Add own config as eslint config so IDEs can take it for linting this project Signed-off-by: Ferdinand Thiessen --- package.json | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index aa242da..4686457 100644 --- a/package.json +++ b/package.json @@ -8,8 +8,8 @@ "url": "git+https://github.com/nextcloud/eslint-config.git" }, "scripts": { - "lint": "eslint -c index.js *.js", - "lint:fix": "eslint -c index.js --fix *.js", + "lint": "eslint parts *.js", + "lint:fix": "eslint --fix parts *.js", "test": "jest" }, "peerDependencies": { @@ -65,6 +65,9 @@ "node": "^20.0.0", "npm": "^9.0.0" }, + "eslintConfig": { + "extends": "./index.js" + }, "jest": { "preset": "ts-jest", "testEnvironment": "node", From 96662f16597bfe670fcb4a64575386874fefea9d Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Tue, 27 Jun 2023 17:23:32 +0200 Subject: [PATCH 2/2] chore: Fix linting issues Signed-off-by: Ferdinand Thiessen --- parts/base.js | 186 ++++++++++++++++++++++---------------------- parts/typescript.js | 70 ++++++++--------- parts/vue.js | 79 ++++++++++--------- 3 files changed, 167 insertions(+), 168 deletions(-) diff --git a/parts/base.js b/parts/base.js index 9487d8c..a8ee911 100644 --- a/parts/base.js +++ b/parts/base.js @@ -1,96 +1,96 @@ /** Base rules */ module.exports = { - root: true, - env: { - browser: true, - commonjs: true, - es6: true, - node: true, - // Allow jest syntax in the src folder - jest: true, - }, - parser: '@babel/eslint-parser', - parserOptions: { - requireConfigFile: false, - }, - extends: [ - 'eslint:recommended', - 'plugin:import/errors', - 'plugin:import/warnings', - 'plugin:n/recommended', - 'plugin:@nextcloud/recommended', - 'plugin:jsdoc/recommended', - 'standard', - ], - settings: { - 'import/resolver': { - node: { - paths: ['src'], - extensions: ['.js', '.vue'], - }, - exports: { - conditions: ['import'], - }, - }, - jsdoc: { - tagNamePreference: { - returns: 'return', - }, - mode: 'typescript', - }, - }, - plugins: ['vue', 'n', 'jsdoc'], - rules: { - // space before function () - 'space-before-function-paren': ['error', { - anonymous: 'never', - named: 'never', - asyncArrow: 'always', - }], - // stay consistent with array brackets - 'array-bracket-newline': ['error', 'consistent'], - // tabs only for indentation - indent: ['error', 'tab'], - 'no-tabs': ['error', { allowIndentationTabs: true }], - // allow spaces after tabs for alignment - 'no-mixed-spaces-and-tabs': ['error', 'smart-tabs'], - // only debug console - 'no-console': ['error', { allow: ['error', 'warn', 'info', 'debug'] }], - // classes blocks - 'padded-blocks': ['error', { classes: 'always' }], - // always have the operator in front - 'operator-linebreak': ['error', 'before'], - // ternary on multiline - 'multiline-ternary': ['error', 'always-multiline'], - // force proper JSDocs - 'jsdoc/require-returns': 0, - 'jsdoc/require-returns-description': 0, - 'jsdoc/tag-lines': ['off'], - // disallow use of "var" - 'no-var': 'error', - // suggest using const - 'prefer-const': 'error', - // es6 import/export and require - 'n/no-unpublished-require': ['off'], - 'n/no-unsupported-features/es-syntax': ['off'], - // always add a trailing comma (for diff readability) - 'comma-dangle': ['warn', 'always-multiline'], - // Allow shallow import of @vue/test-utils and @testing-library/vue in order to be able to use it in - // the src folder - 'n/no-unpublished-import': ['error', { - allowModules: ['@vue/test-utils', '@testing-library/vue'], - }], - // require object literal shorthand syntax - 'object-shorthand': ['error', 'always'], - // Warn when file extensions are not used on import paths - 'import/extensions': ['warn', 'always', { - ignorePackages: true, - }], - // ignore camelcase for __webpack variables - camelcase: ['error', { - allow: ['^UNSAFE_', '^__webpack_'], - properties: 'never', - ignoreGlobals: true, - }], - }, + root: true, + env: { + browser: true, + commonjs: true, + es6: true, + node: true, + // Allow jest syntax in the src folder + jest: true, + }, + parser: '@babel/eslint-parser', + parserOptions: { + requireConfigFile: false, + }, + extends: [ + 'eslint:recommended', + 'plugin:import/errors', + 'plugin:import/warnings', + 'plugin:n/recommended', + 'plugin:@nextcloud/recommended', + 'plugin:jsdoc/recommended', + 'standard', + ], + settings: { + 'import/resolver': { + node: { + paths: ['src'], + extensions: ['.js', '.vue'], + }, + exports: { + conditions: ['import'], + }, + }, + jsdoc: { + tagNamePreference: { + returns: 'return', + }, + mode: 'typescript', + }, + }, + plugins: ['vue', 'n', 'jsdoc'], + rules: { + // space before function () + 'space-before-function-paren': ['error', { + anonymous: 'never', + named: 'never', + asyncArrow: 'always', + }], + // stay consistent with array brackets + 'array-bracket-newline': ['error', 'consistent'], + // tabs only for indentation + indent: ['error', 'tab'], + 'no-tabs': ['error', { allowIndentationTabs: true }], + // allow spaces after tabs for alignment + 'no-mixed-spaces-and-tabs': ['error', 'smart-tabs'], + // only debug console + 'no-console': ['error', { allow: ['error', 'warn', 'info', 'debug'] }], + // classes blocks + 'padded-blocks': ['error', { classes: 'always' }], + // always have the operator in front + 'operator-linebreak': ['error', 'before'], + // ternary on multiline + 'multiline-ternary': ['error', 'always-multiline'], + // force proper JSDocs + 'jsdoc/require-returns': 0, + 'jsdoc/require-returns-description': 0, + 'jsdoc/tag-lines': ['off'], + // disallow use of "var" + 'no-var': 'error', + // suggest using const + 'prefer-const': 'error', + // es6 import/export and require + 'n/no-unpublished-require': ['off'], + 'n/no-unsupported-features/es-syntax': ['off'], + // always add a trailing comma (for diff readability) + 'comma-dangle': ['warn', 'always-multiline'], + // Allow shallow import of @vue/test-utils and @testing-library/vue in order to be able to use it in + // the src folder + 'n/no-unpublished-import': ['error', { + allowModules: ['@vue/test-utils', '@testing-library/vue'], + }], + // require object literal shorthand syntax + 'object-shorthand': ['error', 'always'], + // Warn when file extensions are not used on import paths + 'import/extensions': ['warn', 'always', { + ignorePackages: true, + }], + // ignore camelcase for __webpack variables + camelcase: ['error', { + allow: ['^UNSAFE_', '^__webpack_'], + properties: 'never', + ignoreGlobals: true, + }], + }, } diff --git a/parts/typescript.js b/parts/typescript.js index 1f5b2fe..4a729ea 100644 --- a/parts/typescript.js +++ b/parts/typescript.js @@ -1,37 +1,37 @@ /** Rules for typescript */ module.exports = { - files: ['**/*.ts', '**/*.cts', '**/*.mts', '**/*.tsx'], - extends: [ - '@vue/eslint-config-typescript/recommended', - 'plugin:import/typescript', - ], - parser: '@typescript-eslint/parser', - parserOptions: {}, - rules: { - 'n/no-missing-import': 'off', - 'import/extensions': 'off', - 'jsdoc/check-tag-names': [ - 'warn', { - // for projects using typedoc - definedTags: [ - 'notExported', - 'packageDocumentation', - ], - }, - ], - // Does not make sense with TypeScript - 'jsdoc/require-param-type': 'off', - '@typescript-eslint/no-empty-function': 'off', - }, - settings: { - 'import/resolver': { - typescript: { - alwaysTryTypes: true, - }, - node: { - paths: ['src'], - extensions: ['.(m|c)?js', '.ts', '.tsx', '.vue'], - }, - }, - }, -} \ No newline at end of file + files: ['**/*.ts', '**/*.cts', '**/*.mts', '**/*.tsx'], + extends: [ + '@vue/eslint-config-typescript/recommended', + 'plugin:import/typescript', + ], + parser: '@typescript-eslint/parser', + parserOptions: {}, + rules: { + 'n/no-missing-import': 'off', + 'import/extensions': 'off', + 'jsdoc/check-tag-names': [ + 'warn', { + // for projects using typedoc + definedTags: [ + 'notExported', + 'packageDocumentation', + ], + }, + ], + // Does not make sense with TypeScript + 'jsdoc/require-param-type': 'off', + '@typescript-eslint/no-empty-function': 'off', + }, + settings: { + 'import/resolver': { + typescript: { + alwaysTryTypes: true, + }, + node: { + paths: ['src'], + extensions: ['.(m|c)?js', '.ts', '.tsx', '.vue'], + }, + }, + }, +} diff --git a/parts/vue.js b/parts/vue.js index 93427e7..d8678d6 100644 --- a/parts/vue.js +++ b/parts/vue.js @@ -1,42 +1,41 @@ - module.exports = { - files: ['**/*.vue'], - parser: 'vue-eslint-parser', - parserOptions: { - parser: '@babel/eslint-parser', - }, - extends: ['plugin:vue/recommended'], - rules: { - 'vue/html-indent': ['error', 'tab'], - // PascalCase components names for vuejs - // https://vuejs.org/v2/style-guide/#Single-file-component-filename-casing-strongly-recommended - 'vue/component-name-in-template-casing': ['error', 'PascalCase'], - // force name - 'vue/match-component-file-name': ['error', { - extensions: ['jsx', 'vue', 'js'], - shouldMatchCase: true, - }], - // space before self-closing elements - 'vue/html-closing-bracket-spacing': 'error', - // no ending html tag on a new line - 'vue/html-closing-bracket-newline': ['error', { multiline: 'never' }], - // check vue files too - 'n/no-missing-import': ['error', {}], - // code spacing with attributes - 'vue/max-attributes-per-line': ['error', { - singleline: 3, - multiline: 1, - }], - 'vue/first-attribute-linebreak': ['error', { - singleline: 'beside', - multiline: 'beside', - }], - // Allow single-word components names - 'vue/multi-word-component-names': ['off'], - // custom event naming convention - 'vue/custom-event-name-casing': ['error', 'kebab-case', { - // allows custom xxxx:xxx events formats - ignores: ['/^[a-z]+(?:-[a-z]+)*:[a-z]+(?:-[a-z]+)*$/u'], - }], - }, + files: ['**/*.vue'], + parser: 'vue-eslint-parser', + parserOptions: { + parser: '@babel/eslint-parser', + }, + extends: ['plugin:vue/recommended'], + rules: { + 'vue/html-indent': ['error', 'tab'], + // PascalCase components names for vuejs + // https://vuejs.org/v2/style-guide/#Single-file-component-filename-casing-strongly-recommended + 'vue/component-name-in-template-casing': ['error', 'PascalCase'], + // force name + 'vue/match-component-file-name': ['error', { + extensions: ['jsx', 'vue', 'js'], + shouldMatchCase: true, + }], + // space before self-closing elements + 'vue/html-closing-bracket-spacing': 'error', + // no ending html tag on a new line + 'vue/html-closing-bracket-newline': ['error', { multiline: 'never' }], + // check vue files too + 'n/no-missing-import': ['error', {}], + // code spacing with attributes + 'vue/max-attributes-per-line': ['error', { + singleline: 3, + multiline: 1, + }], + 'vue/first-attribute-linebreak': ['error', { + singleline: 'beside', + multiline: 'beside', + }], + // Allow single-word components names + 'vue/multi-word-component-names': ['off'], + // custom event naming convention + 'vue/custom-event-name-casing': ['error', 'kebab-case', { + // allows custom xxxx:xxx events formats + ignores: ['/^[a-z]+(?:-[a-z]+)*:[a-z]+(?:-[a-z]+)*$/u'], + }], + }, }