Skip to content

Commit

Permalink
feat: added workflow config for root imports
Browse files Browse the repository at this point in the history
  • Loading branch information
GoPro16 committed Oct 10, 2019
1 parent 130888c commit 8fedbbb
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ module.exports = {

// eslint-disable-next-line unicorn/expiring-todo-comments
// FIXME: how to test?
// settings: {
settings: {
// react: {
// version: 'detect',
// },
// },
},

plugins: ['promise', 'jest', 'promise', 'unicorn', 'react-hooks'],

Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"files": [
"index.js",
"browser.js",
"workflow.js",
"ts-recommended.js",
"base.js",
"README.md"
Expand All @@ -41,10 +42,12 @@
"@typescript-eslint/eslint-plugin": "^2.3.1",
"@typescript-eslint/parser": "^2.3.1",
"babel-eslint": "^10.0.3",
"babel-plugin-root-import": "^6.4.1",
"eslint": "^6.4.0",
"eslint-config-airbnb": "^18.0.1",
"eslint-config-airbnb-base": "^14.0.0",
"eslint-config-prettier": "^6.3.0",
"eslint-import-resolver-root-import": "^1.0.4",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jest": "^22.17.0",
"eslint-plugin-jsx-a11y": "^6.2.3",
Expand Down
1 change: 1 addition & 0 deletions project/app/components/SomeComp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Used for testing workflow conf
8 changes: 8 additions & 0 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ const eslint = require('eslint');
const find = require('lodash.find');
const baseConf = require('..');
const reactConf = require('../browser');
const workflowConf = require('../workflow');
const reactString = require('./react');
const reactTsString = require('./react-typescript.js');
const baseString = require('./base');
const workflowString = require('./workflow');

function runEslint(string, configuration, fileName) {
const linter = new eslint.CLIEngine({
Expand Down Expand Up @@ -62,4 +64,10 @@ describe('rules', () => {
expect(find(errors, { ruleId: 'react/prop-types'})).toBeUndefined();
expect(find(errors, { ruleId: 'react/jsx-props-no-spreading'})).toBeUndefined();
});

test('workflow', () => {
const errors = runEslint(workflowString(), workflowConf, 'example.tsx');

expect(find(errors, { ruleId: 'import/no-unresolved' })).toBeUndefined();
});
});
3 changes: 3 additions & 0 deletions tests/workflow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = () => `
import SomeComp from '@/components/SomeComp';
`;
15 changes: 15 additions & 0 deletions workflow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const browser = require('./browser');

module.exports = {
...browser,
settings: {
...browser.settings,
'import/resolver': {
'root-import': {
rootPathPrefix: '@/',
rootPathSuffix: 'project/app',
extensions: ['.js', '.jsx', '.tsx', '.ts'],
},
},
},
};

0 comments on commit 8fedbbb

Please sign in to comment.