-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(eslint-config-angular): add import rules (#152)
- Loading branch information
Showing
11 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,26 @@ | ||
module.exports = { | ||
parser: '@typescript-eslint/parser', | ||
plugins: ['@typescript-eslint', 'simple-import-sort', 'eslint-plugin-import'], | ||
settings: { | ||
'import/parsers': { '@typescript-eslint/parser': ['.ts'] }, | ||
'import/resolver': { 'eslint-import-resolver-typescript': true }, | ||
}, | ||
rules: { | ||
'simple-import-sort/imports': 'error', | ||
'simple-import-sort/exports': 'error', | ||
|
||
'import/first': 'error', | ||
'import/exports-last': 'off', | ||
'import/no-default-export': 'off', | ||
'import/newline-after-import': ['error', { count: 1 }], | ||
'import/no-webpack-loader-syntax': 'off', | ||
|
||
/** | ||
* @note: note you must disable the base rule | ||
* as it can report incorrect errors in @typescript-eslint | ||
*/ | ||
'import/no-duplicates': 'off', | ||
'no-duplicate-imports': 'off', | ||
'@typescript-eslint/no-duplicate-imports': 'error', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
packages/eslint-config-angular/test/imports/__fixtures__/imports-happy.fixture.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { rules as _TSLint } from '@typescript-eslint/eslint-plugin'; | ||
import { process as _process } from 'babel-jest'; | ||
|
||
import { _A as A, _B as B } from './shared-imports.fixture'; | ||
|
||
// only for eslint testing | ||
new A(_TSLint); | ||
new B(_process); |
7 changes: 7 additions & 0 deletions
7
packages/eslint-config-angular/test/imports/__fixtures__/imports-unhappy.fixture.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { rules as _TSLint } from '@typescript-eslint/eslint-plugin'; | ||
import { process as _process } from 'babel-jest'; | ||
import { _A as A, _B as B } from './shared-imports.fixture'; | ||
|
||
// only for eslint testing | ||
new A(_TSLint); | ||
new B(_process); |
6 changes: 6 additions & 0 deletions
6
packages/eslint-config-angular/test/imports/__fixtures__/shared-imports.fixture.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export class _A { | ||
constructor(public options: unknown) {} | ||
} | ||
export class _B { | ||
constructor(public options: unknown) {} | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/eslint-config-angular/test/imports/__snapshots__/imports-happy.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`imports / happy path happy 1`] = `""`; |
14 changes: 14 additions & 0 deletions
14
packages/eslint-config-angular/test/imports/__snapshots__/imports-unhappy.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`imports / unhappy path unhappy 1`] = ` | ||
"error: Run autofix to sort these imports! (simple-import-sort/imports) at packages/eslint-config-angular/test/imports/__fixtures__/imports-unhappy.fixture.ts:1:1: | ||
> 1 | import { rules as _TSLint } from '@typescript-eslint/eslint-plugin'; | ||
| ^ | ||
2 | import { process as _process } from 'babel-jest'; | ||
3 | import { _A as A, _B as B } from './shared-imports.fixture'; | ||
4 | | ||
1 error found. | ||
1 error potentially fixable with the \`--fix\` option." | ||
`; |
21 changes: 21 additions & 0 deletions
21
packages/eslint-config-angular/test/imports/imports-happy.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import ESlint from 'eslint'; | ||
import path from 'path'; | ||
|
||
describe('imports / happy path', () => { | ||
const cli = new ESlint.CLIEngine({ | ||
cwd: path.join(__dirname, '..'), | ||
useEslintrc: false, | ||
baseConfig: { | ||
extends: ['../internal/base', '../internal/import'], | ||
}, | ||
}); | ||
|
||
it('happy', () => { | ||
const codeframe = cli.getFormatter('codeframe'); | ||
const report = cli.executeOnFiles([ | ||
path.join(__dirname, './__fixtures__/imports-happy.fixture.ts'), | ||
]); | ||
|
||
expect(codeframe(report.results)).toMatchSnapshot(); | ||
}); | ||
}); |
21 changes: 21 additions & 0 deletions
21
packages/eslint-config-angular/test/imports/imports-unhappy.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import ESlint from 'eslint'; | ||
import path from 'path'; | ||
|
||
describe('imports / unhappy path', () => { | ||
const cli = new ESlint.CLIEngine({ | ||
cwd: path.join(__dirname, '..'), | ||
useEslintrc: false, | ||
baseConfig: { | ||
extends: ['../internal/base', '../internal/import'], | ||
}, | ||
}); | ||
|
||
it('unhappy', () => { | ||
const codeframe = cli.getFormatter('codeframe'); | ||
const report = cli.executeOnFiles([ | ||
path.join(__dirname, './__fixtures__/imports-unhappy.fixture.ts'), | ||
]); | ||
|
||
expect(codeframe(report.results)).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters