Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Use file type based lint rules #621

Merged
merged 2 commits into from
Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions src/config/eslintrc-js.js
Original file line number Diff line number Diff line change
@@ -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
}
}
2 changes: 1 addition & 1 deletion src/config/eslintrc-ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]
}
63 changes: 15 additions & 48 deletions src/config/eslintrc.js
Original file line number Diff line number Diff line change
@@ -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')
}
]
}
2 changes: 1 addition & 1 deletion src/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})

Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/js+ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "my-project"
}
5 changes: 5 additions & 0 deletions test/fixtures/js+ts/src/another.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { hello } from './typed'

export const main = ():void => {
hello('world')
}
7 changes: 7 additions & 0 deletions test/fixtures/js+ts/src/some.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict'

const main = () => {

}

module.exports = main
3 changes: 3 additions & 0 deletions test/fixtures/js+ts/src/typed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const hello = (name:string):string => {
return `Hello ${name}`
}
5 changes: 5 additions & 0 deletions test/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})