From cb3413d631520943e056ab9f11c2315c2f2ac1c5 Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Fri, 7 Aug 2020 16:54:11 -0700 Subject: [PATCH 1/2] feat: override lint config by file type --- src/config/eslintrc-js.js | 51 +++++++++++++++++++++++++++++++ src/config/eslintrc-ts.js | 2 +- src/config/eslintrc.js | 63 ++++++++++----------------------------- src/lint.js | 2 +- 4 files changed, 68 insertions(+), 50 deletions(-) create mode 100644 src/config/eslintrc-js.js diff --git a/src/config/eslintrc-js.js b/src/config/eslintrc-js.js new file mode 100644 index 000000000..4d514c8d6 --- /dev/null +++ b/src/config/eslintrc-js.js @@ -0,0 +1,51 @@ +'use strict' + +module.exports = { + extends: 'standard', + parserOptions: { + sourceType: 'script' + }, + globals: { + self: true, + mocha: true + }, + plugins: [ + 'no-only-tests' + ], + rules: { + strict: [2, 'safe'], + curly: 'error', + 'block-scoped-var': 2, + complexity: 1, + 'default-case': 2, + 'dot-notation': 1, + 'guard-for-in': 1, + 'linebreak-style': [1, 'unix'], + 'no-alert': 2, + 'no-case-declarations': 2, + 'no-console': 2, + 'no-constant-condition': 2, + 'no-continue': 1, + 'no-div-regex': 2, + 'no-empty': 1, + 'no-empty-pattern': 2, + 'no-extra-semi': 2, + 'no-implicit-coercion': 2, + 'no-labels': 2, + 'no-loop-func': 2, + 'no-nested-ternary': 1, + 'no-only-tests/no-only-tests': 2, + 'no-script-url': 2, + 'no-warning-comments': 1, + 'quote-props': [2, 'as-needed'], + 'require-yield': 2, + 'max-nested-callbacks': [2, 4], + 'max-depth': [2, 4], + 'valid-jsdoc': [2, { + requireReturn: false, + requireParamDescription: false, + requireReturnDescription: false + }], + 'require-await': 2 + } +} diff --git a/src/config/eslintrc-ts.js b/src/config/eslintrc-ts.js index f068824da..3b60b9d44 100644 --- a/src/config/eslintrc-ts.js +++ b/src/config/eslintrc-ts.js @@ -7,7 +7,7 @@ module.exports = { }, plugins: ['@typescript-eslint'], extends: [ - fromAegir('src/config/eslintrc.js'), + fromAegir('src/config/eslintrc-js.js'), 'plugin:@typescript-eslint/recommended' ] } diff --git a/src/config/eslintrc.js b/src/config/eslintrc.js index 4d514c8d6..fa8a08c39 100644 --- a/src/config/eslintrc.js +++ b/src/config/eslintrc.js @@ -1,51 +1,18 @@ 'use strict' - +const { fromAegir } = require('../utils') module.exports = { - extends: 'standard', - parserOptions: { - sourceType: 'script' - }, - globals: { - self: true, - mocha: true - }, - plugins: [ - 'no-only-tests' - ], - rules: { - strict: [2, 'safe'], - curly: 'error', - 'block-scoped-var': 2, - complexity: 1, - 'default-case': 2, - 'dot-notation': 1, - 'guard-for-in': 1, - 'linebreak-style': [1, 'unix'], - 'no-alert': 2, - 'no-case-declarations': 2, - 'no-console': 2, - 'no-constant-condition': 2, - 'no-continue': 1, - 'no-div-regex': 2, - 'no-empty': 1, - 'no-empty-pattern': 2, - 'no-extra-semi': 2, - 'no-implicit-coercion': 2, - 'no-labels': 2, - 'no-loop-func': 2, - 'no-nested-ternary': 1, - 'no-only-tests/no-only-tests': 2, - 'no-script-url': 2, - 'no-warning-comments': 1, - 'quote-props': [2, 'as-needed'], - 'require-yield': 2, - 'max-nested-callbacks': [2, 4], - 'max-depth': [2, 4], - 'valid-jsdoc': [2, { - requireReturn: false, - requireParamDescription: false, - requireReturnDescription: false - }], - 'require-await': 2 - } + overrides: [ + { + files: [ + '**/*.js' + ], + extends: fromAegir('src/config/eslintrc-js.js') + }, + { + files: [ + '**/*.ts' + ], + extends: fromAegir('src/config/eslintrc-ts.js') + } + ] } diff --git a/src/lint.js b/src/lint.js index d1906d693..06a10e235 100644 --- a/src/lint.js +++ b/src/lint.js @@ -83,7 +83,7 @@ function checkDependencyVersions () { function runLinter (opts = {}) { const cli = new CLIEngine({ useEslintrc: true, - baseConfig: opts.ts ? require('./config/eslintrc-ts.js') : require('./config/eslintrc.js'), + baseConfig: require('./config/eslintrc.js'), fix: opts.fix }) From 1d965af97b768e50fe0381ba3c8e953f02e8025c Mon Sep 17 00:00:00 2001 From: Irakli Gozalishvili Date: Fri, 7 Aug 2020 17:28:59 -0700 Subject: [PATCH 2/2] fix: use file type based lint rules --- test/fixtures/js+ts/package.json | 3 +++ test/fixtures/js+ts/src/another.ts | 5 +++++ test/fixtures/js+ts/src/some.js | 7 +++++++ test/fixtures/js+ts/src/typed.ts | 3 +++ test/lint.js | 5 +++++ 5 files changed, 23 insertions(+) create mode 100644 test/fixtures/js+ts/package.json create mode 100644 test/fixtures/js+ts/src/another.ts create mode 100644 test/fixtures/js+ts/src/some.js create mode 100644 test/fixtures/js+ts/src/typed.ts diff --git a/test/fixtures/js+ts/package.json b/test/fixtures/js+ts/package.json new file mode 100644 index 000000000..71126e8a9 --- /dev/null +++ b/test/fixtures/js+ts/package.json @@ -0,0 +1,3 @@ +{ + "name": "my-project" +} \ No newline at end of file diff --git a/test/fixtures/js+ts/src/another.ts b/test/fixtures/js+ts/src/another.ts new file mode 100644 index 000000000..71eac7af2 --- /dev/null +++ b/test/fixtures/js+ts/src/another.ts @@ -0,0 +1,5 @@ +import { hello } from './typed' + +export const main = ():void => { + hello('world') +} diff --git a/test/fixtures/js+ts/src/some.js b/test/fixtures/js+ts/src/some.js new file mode 100644 index 000000000..3099cfdee --- /dev/null +++ b/test/fixtures/js+ts/src/some.js @@ -0,0 +1,7 @@ +'use strict' + +const main = () => { + +} + +module.exports = main diff --git a/test/fixtures/js+ts/src/typed.ts b/test/fixtures/js+ts/src/typed.ts new file mode 100644 index 000000000..88d36376c --- /dev/null +++ b/test/fixtures/js+ts/src/typed.ts @@ -0,0 +1,3 @@ +export const hello = (name:string):string => { + return `Hello ${name}` +} diff --git a/test/lint.js b/test/lint.js index 28dad0ba8..57302b6d4 100644 --- a/test/lint.js +++ b/test/lint.js @@ -161,4 +161,9 @@ describe('lint', () => { await expect(lint({ silent: true })).to.eventually.be.rejectedWith('Lint errors') }) + + it('should lint ts and js with different parsers rules', async () => { + process.chdir(path.join(__dirname, './fixtures/js+ts/')) + await lint() + }) })