Skip to content

Commit

Permalink
feat(eslint-config): set import/no-cycle to error (#206)
Browse files Browse the repository at this point in the history
* feat(eslint-config): set import/no-cycle to error

* test(eslint-config): add import-happy & import-unhappy tests
  • Loading branch information
ddubrava authored Oct 25, 2022
1 parent 3a324b1 commit afab74b
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/eslint-config/internal/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ module.exports = {
],
'import/order': ['warn', { groups: [['builtin', 'external', 'internal']] }],
'import/no-extraneous-dependencies': 'off', // need fine tuning
'import/no-cycle': 'off',
'import/no-cycle': 'error',
},
};
1 change: 1 addition & 0 deletions packages/eslint-config/test/import/__fixtures__/dep-a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function a() {}
3 changes: 3 additions & 0 deletions packages/eslint-config/test/import/__fixtures__/dep-b.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import './import-unhappy.fixture';

export function b() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { a } from './dep-a';

a();
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { b } from './dep-b';

b();
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`import / happy path happy 1`] = `""`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`import / unhappy path unhappy 1`] = `
"error: Dependency cycle detected (import/no-cycle) at packages/eslint-config/test/import/__fixtures__/import-unhappy.fixture.js:1:1:
> 1 | import { b } from './dep-b';
| ^
2 |
3 | b();
4 |
1 error found."
`;
27 changes: 27 additions & 0 deletions packages/eslint-config/test/import/import-happy.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import ESlint from 'eslint';
import path from 'path';

describe('import / happy path', () => {
const cli = new ESlint.CLIEngine({
cwd: path.join(__dirname, '..'),
useEslintrc: false,
baseConfig: {
extends: ['../internal/import'],
parserOptions: {
sourceType: 'module',
},
env: {
es6: true,
},
},
});

it('happy', () => {
const codeframe = cli.getFormatter('codeframe');
const report = cli.executeOnFiles([
path.join(__dirname, './__fixtures__/import-happy.fixture.js'),
]);

expect(codeframe(report.results)).toMatchSnapshot();
});
});
27 changes: 27 additions & 0 deletions packages/eslint-config/test/import/import-unhappy.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import ESlint from 'eslint';
import path from 'path';

describe('import / unhappy path', () => {
const cli = new ESlint.CLIEngine({
cwd: path.join(__dirname, '..'),
useEslintrc: false,
baseConfig: {
extends: ['../internal/import'],
parserOptions: {
sourceType: 'module',
},
env: {
es6: true,
},
},
});

it('unhappy', () => {
const codeframe = cli.getFormatter('codeframe');
const report = cli.executeOnFiles([
path.join(__dirname, './__fixtures__/import-unhappy.fixture.js'),
]);

expect(codeframe(report.results)).toMatchSnapshot();
});
});

0 comments on commit afab74b

Please sign in to comment.