Skip to content

Commit

Permalink
feat(eslint-config-angular): add import rules (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode committed Nov 23, 2021
1 parent 42a23c1 commit be87476
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 0 deletions.
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions packages/eslint-config-angular/internal/import.js
@@ -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',
},
};
3 changes: 3 additions & 0 deletions packages/eslint-config-angular/package.json
Expand Up @@ -23,6 +23,9 @@
"type": "git",
"url": "https://github.com/TinkoffCreditSystems/linters.git"
},
"dependencies": {
"eslint-plugin-simple-import-sort": "^7.0.0"
},
"peerDependencies": {
"@tinkoff/eslint-config": "^1.13.2",
"@typescript-eslint/eslint-plugin": "^5.4.0",
Expand Down
@@ -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);
@@ -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);
@@ -0,0 +1,6 @@
export class _A {
constructor(public options: unknown) {}
}
export class _B {
constructor(public options: unknown) {}
}
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`imports / happy path happy 1`] = `""`;
@@ -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 packages/eslint-config-angular/test/imports/imports-happy.test.js
@@ -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();
});
});
@@ -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();
});
});
1 change: 1 addition & 0 deletions tsconfig.json
@@ -1,6 +1,7 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"moduleResolution": "node",
"outDir": "tslint/rules",
"module": "es6",
"target": "es6",
Expand Down

0 comments on commit be87476

Please sign in to comment.