@talend/eslint-plugin
Advanced tools
Comparing version 0.0.1 to 0.1.0
@@ -5,3 +5,3 @@ # Check if the import depth let your code be UMD build compliant (talend-import-depth) | ||
At the same time, we wanna keep the tree shaking approach possible. | ||
At the same time, we wanna keep the tree shaking approach possible in components libraries like @talend/react-components. | ||
@@ -11,2 +11,3 @@ To get both we have concluded that we can afford both if we stick to import to the first level of a module, | ||
Note on the project side like @talend/dataset we have issues that the components can not be reused outside, you have to initiate the whole module. | ||
@@ -21,2 +22,3 @@ ## Rule Details | ||
import ListComposition from '@talend/react-components/lib/List/ListComposition'; | ||
import match from '@talend/react-cmf/lib/matchPath'; | ||
``` | ||
@@ -28,3 +30,6 @@ | ||
import List from '@talend/react-components/lib/List'; | ||
import cmf from '@talend/react-cmf'; | ||
const { ListComposition } = List; | ||
const match = cmf.router.matchPath; | ||
``` | ||
@@ -31,0 +36,0 @@ |
{ | ||
"name": "@talend/eslint-plugin", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Contains internal rules used at Talend", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -20,2 +20,5 @@ /** | ||
// are considered as components lib | ||
const COMPONENTS = ['react-components', 'react-containers']; | ||
function checkAndReport(context, node, value, messageId) { | ||
@@ -26,3 +29,9 @@ if (!value.startsWith('@talend')) { | ||
const splited = value.split('/'); | ||
if (splited.length >= 5) { | ||
let max_length = 2; | ||
let should = `${splited[0]}/${splited[1]}`; | ||
if (COMPONENTS.indexOf(splited[1]) !== -1) { | ||
max_length = 4 | ||
should = `${should}/${splited[2]}/${splited[3]}`; | ||
} | ||
if (splited.length > max_length) { | ||
context.report({ | ||
@@ -33,3 +42,3 @@ node, | ||
module: value, | ||
should: '/' + splited.splice(2, 2).join('/'), | ||
should, | ||
}, | ||
@@ -58,4 +67,3 @@ }); | ||
fixable: null, | ||
schema: [ | ||
], | ||
schema: {}, | ||
messages: { | ||
@@ -67,3 +75,3 @@ tooDeep: "'{{module}}' import too deep. No more than {{should}}", | ||
create: function create(context) { | ||
return { | ||
return { | ||
ImportDeclaration: handleImports(context), | ||
@@ -70,0 +78,0 @@ }; |
@@ -20,5 +20,22 @@ /** | ||
valid: [ | ||
{ code: "import List from '@talend/react-components/lib/List';", parser: require.resolve('babel-eslint') }, | ||
{ code: "import SidePanel from '@talend/react-components/lib/SidePanel';", parser: require.resolve('babel-eslint') }, | ||
{ code: "import { SidePanel } from '@talend/react-components';", parser: require.resolve('babel-eslint') }, | ||
{ | ||
code: "import List from '@talend/react-components/lib/List';", | ||
parser: require.resolve('babel-eslint'), | ||
}, | ||
{ | ||
code: "import SidePanel from '@talend/react-components/lib/SidePanel';", | ||
parser: require.resolve('babel-eslint'), | ||
}, | ||
{ | ||
code: "import { SidePanel } from '@talend/react-components';", | ||
parser: require.resolve('babel-eslint'), | ||
}, | ||
{ | ||
code: "import cmf, { cmfConnect } from '@talend/react-cmf';", | ||
parser: require.resolve('babel-eslint'), | ||
}, | ||
{ | ||
code: "import stepper from '@talend/react-faceted-search';", | ||
parser: require.resolve('babel-eslint'), | ||
}, | ||
], | ||
@@ -28,7 +45,8 @@ | ||
{ | ||
code: "import ListComposition from '@talend/react-components/lib/List/ListComposition';", | ||
parser: require.resolve('babel-eslint'), | ||
code: "import ListComposition from '@talend/react-components/lib/List/ListComposition';", | ||
parser: require.resolve('babel-eslint'), | ||
errors: [ | ||
{ | ||
message: "'@talend/react-components/lib/List/ListComposition' import too deep. No more than /lib/List", | ||
message: | ||
"'@talend/react-components/lib/List/ListComposition' import too deep. No more than @talend/react-components/lib/List", | ||
type: 'ImportDeclaration', | ||
@@ -38,3 +56,25 @@ }, | ||
}, | ||
{ | ||
code: "import match from '@talend/react-cmf/lib/matchPath';", | ||
parser: require.resolve('babel-eslint'), | ||
errors: [ | ||
{ | ||
message: | ||
"'@talend/react-cmf/lib/matchPath' import too deep. No more than @talend/react-cmf", | ||
type: 'ImportDeclaration', | ||
}, | ||
], | ||
}, | ||
{ | ||
code: "import { I18N_DOMAIN_FORMS } from '@talend/react-forms/lib/UIForm';", | ||
parser: require.resolve('babel-eslint'), | ||
errors: [ | ||
{ | ||
message: | ||
"'@talend/react-forms/lib/UIForm' import too deep. No more than @talend/react-forms", | ||
type: 'ImportDeclaration', | ||
}, | ||
], | ||
}, | ||
], | ||
}); |
6997
155