Skip to content

Commit 4ccebf4

Browse files
joshblacktw15egan
andauthored
feat(eslint-config-carbon): update config and externalize package (#6169)
* refactor(eslint): update structure to use plugin folders * feat(eslint): add support for overrides * fix(project): address eslint violations * feat(eslint): enable no-useless-fragment * chore: remove jsx-a11y overrides * chore(lint): begin fixing linting errors * chore(tests): update snapshots, merge with master * chore(lint): fix linting errors through listbox * chore(lint): fix linting errors through overflow menu * chore(lint): fix linting errors through UI Shell * chore(snapshot): update snapshots * chore(lint): fix vanilla linting errors Co-authored-by: TJ Egan <tw15egan@gmail.com>
1 parent b7eb9e5 commit 4ccebf4

File tree

102 files changed

+1080
-387
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+1080
-387
lines changed
Binary file not shown.
Binary file not shown.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"enzyme-adapter-react-16": "^1.14.0",
5858
"enzyme-to-json": "^3.3.5",
5959
"eslint": "^6.8.0",
60-
"eslint-config-carbon": "10.7.0",
60+
"eslint-config-carbon": "2.0.0",
6161
"fs-extra": "^8.1.0",
6262
"glob": "^7.1.4",
6363
"husky": "^4.0.10",

packages/components/demo/js/components/ComponentExample/ComponentExample.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class ComponentExample extends Component {
6666
this._instantiateComponents();
6767
}
6868

69+
// eslint-disable-next-line react/no-deprecated
6970
componentWillUpdate({ component, htmlFile }) {
7071
const { component: prevComponent, htmlFile: prevHtmlFile } = this.props;
7172
if (prevComponent !== component || prevHtmlFile !== htmlFile) {

packages/components/demo/js/components/RootPage.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ class RootPage extends Component {
195195
currentTheme: themeSwitcherItems[0].id,
196196
};
197197

198+
// eslint-disable-next-line react/prop-types
198199
static getDerivedStateFromProps({ componentItems, isComponentsX }, state) {
199200
const {
200201
prevComponentItems,
@@ -517,6 +518,7 @@ class RootPage extends Component {
517518
value={currentTheme}
518519
onChange={this._handleChangeThemeSwitcherDropdown}>
519520
{themeSwitcherItems.map(({ id, text }) => (
521+
// eslint-disable-next-line react/jsx-key
520522
<DropdownItem itemText={text} value={id} />
521523
))}
522524
</Dropdown>

packages/eslint-config-carbon/base.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Copyright IBM Corp. 2018, 2018
3+
*
4+
* This source code is licensed under the Apache-2.0 license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
'use strict';
9+
10+
module.exports = {
11+
parser: 'babel-eslint',
12+
extends: ['eslint:recommended', require.resolve('./plugins/jsdoc')],
13+
rules: {
14+
// Handle cases where we are destructuring but may not be using the initial
15+
// variables
16+
'no-unused-vars': [
17+
'error',
18+
{
19+
args: 'after-used',
20+
argsIgnorePattern: '^_',
21+
varsIgnorePattern: '^_',
22+
},
23+
],
24+
},
25+
env: {
26+
node: true,
27+
browser: true,
28+
es6: true,
29+
jest: true,
30+
jasmine: true,
31+
},
32+
globals: {
33+
__DEV__: true,
34+
},
35+
};

packages/eslint-config-carbon/index.js

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -8,68 +8,5 @@
88
'use strict';
99

1010
module.exports = {
11-
parser: 'babel-eslint',
12-
extends: ['eslint:recommended', 'plugin:jsx-a11y/recommended'],
13-
plugins: ['react', 'jsdoc', 'jsx-a11y', 'react-hooks'],
14-
rules: {
15-
// Handle cases where we are destructuring but may not be using the initial
16-
// variables
17-
'no-unused-vars': [
18-
'error',
19-
{
20-
args: 'after-used',
21-
argsIgnorePattern: '^_',
22-
varsIgnorePattern: '^_',
23-
},
24-
],
25-
'react/jsx-uses-vars': 1,
26-
'react/jsx-uses-react': 1,
27-
'react/no-find-dom-node': 1,
28-
'react/no-typos': 2,
29-
'react-hooks/rules-of-hooks': 'error',
30-
'react-hooks/exhaustive-deps': 'error',
31-
'jsdoc/check-param-names': 2,
32-
'jsdoc/check-tag-names': [
33-
'error',
34-
{
35-
definedTags: ['jest-environment'],
36-
},
37-
],
38-
'jsdoc/check-types': 2,
39-
'jsx-a11y/no-static-element-interactions': 1,
40-
'jsx-a11y/no-noninteractive-element-interactions': 1,
41-
'jsx-a11y/click-events-have-key-events': 1,
42-
'jsx-a11y/anchor-is-valid': 1,
43-
'jsx-a11y/interactive-supports-focus': 1,
44-
'jsx-a11y/label-has-for': [
45-
1,
46-
{
47-
components: ['Label'],
48-
required: {
49-
some: ['nesting', 'id'],
50-
},
51-
allowChildren: true,
52-
},
53-
],
54-
},
55-
env: {
56-
node: true,
57-
browser: true,
58-
es6: true,
59-
jest: true,
60-
jasmine: true,
61-
},
62-
globals: {
63-
__DEV__: true,
64-
},
65-
settings: {
66-
jsdoc: {
67-
tagNamePreference: {
68-
augments: 'extends',
69-
},
70-
},
71-
react: {
72-
version: 'detect',
73-
},
74-
},
11+
extends: [require.resolve('./base'), require.resolve('./plugins/react')],
7512
};

packages/eslint-config-carbon/package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
{
22
"name": "eslint-config-carbon",
33
"private": true,
4-
"version": "10.7.0",
4+
"version": "2.0.0",
55
"license": "Apache-2.0",
66
"main": "index.js",
77
"repository": "https://github.com/carbon-design-system/carbon/tree/master/packages/eslint-config-carbon",
88
"bugs": "https://github.com/carbon-design-system/carbon/issues",
9+
"files": [
10+
"plugins",
11+
"index.js",
12+
"react.js",
13+
"vanilla.js"
14+
],
915
"keywords": [
1016
"ibm",
1117
"carbon",
@@ -29,7 +35,7 @@
2935
"eslint-plugin-jsx-a11y": "^6.2.1",
3036
"eslint-plugin-prettier": "^3.1.2",
3137
"eslint-plugin-react": "^7.18.0",
32-
"eslint-plugin-react-hooks": "^2.3.0",
38+
"eslint-plugin-react-hooks": "^4.0.4",
3339
"eslint-restricted-globals": "^0.2.0"
3440
}
3541
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Copyright IBM Corp. 2018, 2018
3+
*
4+
* This source code is licensed under the Apache-2.0 license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
'use strict';
9+
10+
module.exports = {
11+
plugins: ['jsdoc'],
12+
settings: {
13+
jsdoc: {
14+
tagNamePreference: {
15+
augments: 'extends',
16+
},
17+
},
18+
},
19+
rules: {
20+
'jsdoc/check-param-names': 2,
21+
'jsdoc/check-tag-names': [
22+
'error',
23+
{
24+
definedTags: ['jest-environment'],
25+
},
26+
],
27+
'jsdoc/check-types': 2,
28+
},
29+
};
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/**
2+
* Copyright IBM Corp. 2018, 2018
3+
*
4+
* This source code is licensed under the Apache-2.0 license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
'use strict';
9+
10+
module.exports = {
11+
extends: [
12+
'plugin:react/recommended',
13+
'plugin:react-hooks/recommended',
14+
'plugin:jsx-a11y/recommended',
15+
],
16+
plugins: ['react', 'react-hooks'],
17+
settings: {
18+
react: {
19+
version: 'detect',
20+
},
21+
},
22+
parserOptions: {
23+
ecmaFeatures: {
24+
jsx: true,
25+
},
26+
},
27+
rules: {
28+
// react
29+
'react/jsx-uses-vars': 1,
30+
'react/jsx-uses-react': 1,
31+
'react/no-find-dom-node': 1,
32+
'react/jsx-no-useless-fragment': 2,
33+
'react/no-typos': 2,
34+
35+
// react-hooks
36+
'react-hooks/rules-of-hooks': 2,
37+
'react-hooks/exhaustive-deps': 2,
38+
},
39+
overrides: [
40+
// Sometimes we'll want to define a quick component in a story to use as a
41+
// wrapper for a component we're documenting. For example:
42+
//
43+
// function DemoComponent({ children }) {
44+
// return <p>{children}</p>;
45+
// }
46+
//
47+
// In these cases, we don't need to handle prop type validation like we
48+
// would for code we ship to users.
49+
{
50+
files: ['*-story.js'],
51+
rules: {
52+
'react/prop-types': 0,
53+
},
54+
},
55+
56+
// When writing fixtures, we tend to focus on the specific component and
57+
// don't require React in scope as we never end up executing the code. The
58+
// fixtures are often used for asserting transformations on the file
59+
{
60+
files: ['**/fixtures/**/*.js'],
61+
rules: {
62+
'react/react-in-jsx-scope': 0,
63+
},
64+
},
65+
66+
{
67+
files: ['*-test.js'],
68+
rules: {
69+
// We often write inline functions for certain types of props, typically
70+
// `render*` props. For example, `renderIcon={() => <div>test</div>}`
71+
'react/display-name': 0,
72+
73+
// While writing tests, we often write helper components that are meant
74+
// to emulate a specific situation or behavior. These do not require prop
75+
// types as they are not shipped to end-users and are not valuable for
76+
// test authors.
77+
'react/prop-types': 0,
78+
},
79+
},
80+
],
81+
};

0 commit comments

Comments
 (0)