Skip to content

Commit ed89aa4

Browse files
authored
Feature/improve eslint job (#4219)
* use .eslintrc.js * upgrade eslint * use eslint-plugin-markdown v2 * lint js blocks in markdown files * fix lint * add eslint-plugin-react * fix bugs
1 parent ea2a70c commit ed89aa4

File tree

29 files changed

+362
-113
lines changed

29 files changed

+362
-113
lines changed

.eslintrc

Lines changed: 0 additions & 40 deletions
This file was deleted.

.eslintrc.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
module.exports = {
2+
root: true,
3+
extends: ['eslint:recommended', 'plugin:react/recommended'],
4+
parser: '@babel/eslint-parser',
5+
env: {
6+
browser: true,
7+
es6: true,
8+
node: true,
9+
jest: true,
10+
'cypress/globals': true,
11+
},
12+
plugins: ['markdown', 'cypress'],
13+
globals: {
14+
__DEV__: true,
15+
},
16+
rules: {
17+
'no-undef': 2,
18+
'no-unreachable': 2,
19+
'no-unused-vars': 0,
20+
'no-console': 0,
21+
semi: ['error', 'always'],
22+
quotes: ['error', 'single'],
23+
'react/jsx-uses-react': 'off', // no longer needed with new jsx transform
24+
'react/react-in-jsx-scope': 'off', // ditto
25+
},
26+
settings: {
27+
react: {
28+
version: 'detect',
29+
},
30+
},
31+
overrides: [
32+
{ files: ['src/**/*.jsx'] }, // eslint would lint .js only by default
33+
{
34+
files: ['src/content/**/*.{md,mdx}'],
35+
processor: 'markdown/markdown',
36+
},
37+
{
38+
files: ['src/content/**/*.{md,mdx}/*.{js,javascript}'], // we don't lint ts at the moment
39+
rules: {
40+
indent: ['error', 2],
41+
quotes: ['error', 'single'],
42+
'no-undef': 0,
43+
'no-constant-condition': 0,
44+
'no-useless-escape': 0,
45+
'no-dupe-keys': 0,
46+
},
47+
},
48+
],
49+
};

package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
"build-test": "npm run build && http-server dist/",
4343
"test": "npm run lint",
4444
"lint": "run-s lint:*",
45-
"lint:js": "npm run lint-js src",
46-
"lint-js": "eslint --ext .js,.jsx,.md --cache --cache-location .cache/.eslintcache",
45+
"lint:js": "npm run lint-js",
46+
"lint-js": "eslint . --cache --cache-location .cache/.eslintcache",
4747
"lint:markdown": "npm run lint-markdown *.md ./src/content/**/*.md",
4848
"lint-markdown": "markdownlint --rules markdownlint-rule-emphasis-style --config ./.markdownlint.json --ignore './src/content/**/_*.md'",
4949
"lint:social": "alex . -q",
@@ -79,7 +79,7 @@
7979
],
8080
"devDependencies": {
8181
"@babel/core": "^7.11.6",
82-
"@babel/eslint-parser": "^7.11.5",
82+
"@babel/eslint-parser": "^7.12.1",
8383
"@babel/plugin-proposal-class-properties": "^7.10.4",
8484
"@babel/preset-env": "^7.11.5",
8585
"@babel/preset-react": "^7.10.4",
@@ -100,9 +100,10 @@
100100
"directory-tree": "^2.2.4",
101101
"directory-tree-webpack-plugin": "^1.0.2",
102102
"duplexer": "^0.1.1",
103-
"eslint": "^7.8.1",
104-
"eslint-plugin-cypress": "^2.10.3",
105-
"eslint-plugin-markdown": "^1.0.2",
103+
"eslint": "^7.14.0",
104+
"eslint-plugin-cypress": "^2.11.2",
105+
"eslint-plugin-markdown": "^2.0.0-rc.0",
106+
"eslint-plugin-react": "^7.21.5",
106107
"front-matter": "^4.0.2",
107108
"html-loader": "^1.3.0",
108109
"html-webpack-plugin": "^4.4.1",

src/components/Configuration/Configuration.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { Children, isValidElement } from 'react';
22
import { Details } from './components';
3+
import PropTypes from 'prop-types';
34

45
const detailComponentsList = ['link', 'mode', 'entry', 'path', 'filename', 'publicPath', 'library', 'libraryType', 'libraryName', 'advancedLibrary', 'advancedOutput', 'expertOutput', 'expertOutputB', 'expert', 'advancedConditions', 'moduleType', 'advancedActions', 'advancedModule', 'modules', 'alias', 'advancedResolve', 'expertResolve', 'hints', 'devtool', 'target', 'externals', 'externalsType', 'externalsPresets', 'ignoreWarnings', 'stats', 'preset', 'advancedGlobal', 'advancedAssets', 'advancedChunkGroups', 'advancedChunks', 'advancedModules', 'expertModules', 'advancedStatsOptimization', 'advancedOptimization', 'cacheGroupAdvancedSelectors', 'cacheGroupAdvancedEffects', 'advancedSelectors', 'advancedEffects', 'fallbackCacheGroup', 'advanced', 'advancedCaching', 'advancedBuild'];
5-
66
export const Pre = props => {
7+
// eslint-disable-next-line
78
const newChildren = Children.map(props.children.props.children, child => {
89
if (isValidElement(child)) {
910
if (child.props.className.includes('keyword')) {
1011
if (!detailComponentsList.includes(child.props.componentname)) return child;
11-
12+
// eslint-disable-next-line
1213
return <Details children={child.props.children.slice(4, Children.count(child.props.children) - 4)} url={child.props.url} />;
1314
}
1415
}
@@ -26,3 +27,6 @@ export const Pre = props => {
2627
</pre>
2728
);
2829
};
30+
Pre.propTypes = {
31+
32+
};

src/components/Configuration/components.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { isValidElement, Component } from 'react';
22
import Popover from 'react-tiny-popover';
33
import './Configuration.scss';
44
import { timeout } from 'q';
5+
import PropTypes from 'prop-types';
56

67
const DEFAULT_CHILDREN_SIZE = 4;
78

@@ -18,7 +19,6 @@ const addLink = (child, i, url) => {
1819
child
1920
);
2021
};
21-
2222
const Card = ({ body }) => {
2323
return (
2424
<div className="markdown">
@@ -28,8 +28,14 @@ const Card = ({ body }) => {
2828
</div>
2929
);
3030
};
31-
31+
Card.propTypes = {
32+
body: PropTypes.string
33+
};
3234
export class Details extends Component {
35+
static propTypes = {
36+
url: PropTypes.string,
37+
children: PropTypes.arrayOf(PropTypes.node)
38+
}
3339
constructor(props) {
3440
super(props);
3541
this.state = {
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import './Container.scss';
2-
3-
export default (props = {}) => {
2+
import PropTypes from 'prop-types';
3+
Container.propTypes = {
4+
className: PropTypes.string,
5+
children: PropTypes.node
6+
};
7+
export default function Container (props = {}) {
48
let { className = '' } = props;
59

610
return (
711
<div className={ `container ${className}` }>
812
{ props.children }
913
</div>
1014
);
11-
};
15+
}

src/components/Contributors/Contributors.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ import { Component } from 'react';
22
import VisibilitySensor from 'react-visibility-sensor';
33
import SmallIcon from '../../assets/icon-square-small-slack.png';
44
import './Contributors.scss';
5+
import PropTypes from 'prop-types';
56

67
export default class Contributors extends Component {
8+
static propTypes = {
9+
contributors: PropTypes.array
10+
}
711
state = {
812
inView: false
913
}
@@ -18,11 +22,11 @@ export default class Contributors extends Component {
1822
render() {
1923
const { inView } = this.state;
2024
const { contributors } = this.props;
21-
25+
2226
if (!contributors.length) {
2327
return <noscript />;
2428
}
25-
29+
2630
return (
2731
<VisibilitySensor delayedCall
2832
partialVisibility

src/components/Cube/Cube.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ export default class Cube extends Component {
1010
hover: PropTypes.bool,
1111
theme: PropTypes.string,
1212
depth: PropTypes.number,
13-
repeatDelay: PropTypes.number
13+
repeatDelay: PropTypes.number,
14+
className: PropTypes.string,
15+
continuous: PropTypes.bool
1416
};
1517

1618
static defaultProps = {

src/components/Dropdown/Dropdown.jsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import { Component } from 'react';
22
import LanguageIcon from '../../assets/language-icon.svg';
33
import './Dropdown.scss';
4+
import PropTypes from 'prop-types';
45

56
export default class Dropdown extends Component {
7+
static propTypes = {
8+
className: PropTypes.string,
9+
items: PropTypes.array
10+
}
611
state = {
712
active: false
813
};
@@ -32,7 +37,7 @@ export default class Dropdown extends Component {
3237
let activeMod = this.state.active ? 'dropdown__list--active' : '';
3338

3439
return (
35-
<nav
40+
<nav
3641
className={ `dropdown ${className}` }
3742
ref={ el => this.dropdown = el }
3843
onMouseOver={ this._toggle.bind(this, true) }
@@ -59,9 +64,9 @@ export default class Dropdown extends Component {
5964
items.map((item, i) => {
6065
return (
6166
<li key={ item.title }>
62-
<a
67+
<a
6368
onKeyDown={this._handleArrowKeys.bind(this, i, items.length - 1)}
64-
ref={ node => this.links ? this.links.push(node) : this.links = [node] }
69+
ref={ node => this.links ? this.links.push(node) : this.links = [node] }
6570
href={ item.url }>
6671
<span lang={ item.lang }>{ item.title }</span>
6772
</a>

src/components/Logo/Logo.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import Logo from '../../assets/site-logo.svg';
22
import './Logo.scss';
33

4-
export default () => {
4+
export default function LogoComp() {
55
return (
66
<img className="logo" src={ Logo } alt="webpack logo" />
77
);
8-
};
8+
}

src/components/Markdown/Markdown.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import './Markdown.scss';
2+
import PropTypes from 'prop-types';
23

34
const Markdown = props => (
45
<div className="markdown">
56
{ props.children }
67
</div>
78
);
8-
9+
Markdown.propTypes = {
10+
children: PropTypes.node
11+
};
912
export default Markdown;

src/components/Navigation/Navigation.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Import External Dependencies
22
import { Component } from 'react';
33
import Banner from 'react-banner';
4+
import PropTypes from 'prop-types';
45

56
// Import Components
67
import Link from '../Link/Link';
@@ -22,6 +23,11 @@ import StackOverflowIcon from '../../styles/icons/stack-overflow.svg';
2223
const onSearch = () => {};
2324

2425
export default class Navigation extends Component {
26+
static propTypes = {
27+
pathname: PropTypes.string,
28+
links: PropTypes.array,
29+
toggleSidebar: PropTypes.func
30+
}
2531
render() {
2632
let { pathname, links, toggleSidebar } = this.props;
2733

src/components/NotificationBar/NotificationBar.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Container from '../Container/Container';
33
import testLocalStorage from '../../utilities/test-local-storage';
44
import './NotificationBar.scss';
55
import CloseIcon from '../../styles/icons/cross.svg';
6+
import PropTypes from 'prop-types';
67

78
const version = '3';
89
const localStorageIsEnabled = testLocalStorage() !== false;
@@ -15,6 +16,9 @@ const barDismissed = () => {
1516
};
1617

1718
class MessageBar extends Component {
19+
static propTypes = {
20+
onClose: PropTypes.func
21+
}
1822
render() {
1923
return (
2024
<div className="notification-bar">

src/components/Page/Page.jsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Import External Dependencies
22
import { Children, isValidElement, Component } from 'react';
3+
import PropTypes from 'prop-types';
34

45
// Import Components
56
import PageLinks from '../PageLinks/PageLinks';
@@ -13,6 +14,19 @@ import AdjacentPages from './AdjacentPages';
1314
import './Page.scss';
1415

1516
class Page extends Component {
17+
static propTypes = {
18+
title: PropTypes.string,
19+
contributors: PropTypes.array,
20+
related: PropTypes.array,
21+
previous: PropTypes.object,
22+
next: PropTypes.object,
23+
content: PropTypes.oneOfType([
24+
PropTypes.shape({
25+
then: PropTypes.func.isRequired,
26+
default: PropTypes.string
27+
})
28+
])
29+
}
1630
constructor(props) {
1731
super(props);
1832

@@ -72,6 +86,7 @@ class Page extends Component {
7286
contentRender = Children.map(contentRender, child => {
7387
if (isValidElement(child)) {
7488
if (child.props.mdxType === 'pre') {
89+
// eslint-disable-next-line
7590
return <Pre children={child.props.children} />;
7691
}
7792
}

src/components/PageLinks/PageLinks.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import EditIcon from '../../styles/icons/edit.svg';
55

66
const baseURL = 'https://github.com/webpack/webpack.js.org/edit/master/';
77

8-
export default ({
8+
export default function PageLinks({
99
page = {},
1010
...props
11-
}) => {
11+
}) {
1212
const editLink = page.edit || Url.resolve(baseURL, page.path);
1313

1414
// TODO: Make sure we add `repo` / `edit` and address `type` (above)
@@ -35,7 +35,7 @@ export default ({
3535
</button>
3636
</div>
3737
);
38-
};
38+
}
3939

4040
function _handlePrintClick (e) {
4141
e.preventDefault();

0 commit comments

Comments
 (0)