Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set ESlint rules more strict 🚑 #911

Merged
merged 71 commits into from
Jun 6, 2017
Merged
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
0a7163b
ADD stricter eslint rules
ndelangen Apr 17, 2017
26f7ca5
FIX linting
ndelangen Apr 17, 2017
a37eb11
FIX for https://github.com/storybooks/storybook/commit/fc7e09b810678c…
ndelangen Apr 28, 2017
32288f9
Merge branch 'master' into eslint-strict
ndelangen Apr 28, 2017
b801d6f
FIX linting
ndelangen Apr 28, 2017
d22d23a
fixes linting in storyshots
theinterned Apr 28, 2017
1599862
FIX: listing in the `storybook-ui` package
theinterned Apr 28, 2017
84f1e37
fix: failing Panel.js test in add-knobs
theinterned Apr 28, 2017
5deb96e
resolves listing in Stories component of storybook-ui
theinterned Apr 28, 2017
59daa5c
fix: test for storybook-ui let_panel/index
theinterned Apr 28, 2017
0d2cab0
fix: eslint -- resolves globals using the `global` module rather than…
theinterned Apr 28, 2017
5219498
fix: linting in `react-storybook` package
theinterned Apr 29, 2017
0f65908
fix: adds missing `ws` dep to `react-native-storybook`
theinterned Apr 29, 2017
55a67e7
fix: adds missing `global` dep to `react-native-storybook`
theinterned Apr 29, 2017
52b8490
fix: linting in `react-native-storybook` package
theinterned Apr 29, 2017
90edfdf
fix: listing in `getstorybook` package
theinterned Apr 29, 2017
7909848
fix: adds `react: "*"` as a peer dep for `decorator-cantered` to fix …
theinterned Apr 29, 2017
dd70952
fix: adds `global` dep to `channel-postmessage` and `channel-websocke…
theinterned Apr 29, 2017
45353ff
fix: linting in `channel-websockets`
theinterned Apr 29, 2017
fc84af7
fix: peer dep for `@kadira/storybook-addons` wasn't resolving properl…
theinterned Apr 29, 2017
2538232
fix: listing of `add-on-notes`
theinterned Apr 29, 2017
d1d2bfa
fix: linting for `addon-knobs` package
theinterned Apr 30, 2017
fd282e2
fix: listing for `addon-info` package
theinterned May 7, 2017
de8012f
fix: adds `global` dep to resolve linting
theinterned May 7, 2017
93dc42c
fix: linting `no-underscore-dangle` faux-private members in `addons` …
theinterned May 7, 2017
377d575
fix: linting in `addon-graphql` package
theinterned May 8, 2017
0e6bfd2
fix: linting in `addon-comments` package
theinterned May 8, 2017
2c88ace
Merge branch 'master' into eslint-strict
ndelangen May 9, 2017
0d79ae5
CHANGED eslint-config-airbnb for a fork waiting for publish
ndelangen May 9, 2017
45ba7ba
Merge branch 'master' into eslint-strict
ndelangen May 11, 2017
09747c6
Merge branch 'master' into eslint-strict
ndelangen May 17, 2017
2bcaae9
FIX linting
ndelangen May 18, 2017
d55bc6a
FIX linting
ndelangen May 18, 2017
22b4b94
FIX linting
ndelangen May 18, 2017
e03aa55
FIX linting
ndelangen May 18, 2017
22a9288
FIX linting
ndelangen May 18, 2017
24544af
FIX linting
ndelangen May 18, 2017
03c56b4
FIX linting
ndelangen May 18, 2017
0142e4b
FIX linting
ndelangen May 18, 2017
5e0b17a
FIX linting
ndelangen May 18, 2017
600cbce
FIX linting
ndelangen May 18, 2017
08a49db
Merge branch 'master' into eslint-strict
ndelangen May 19, 2017
af1b0c1
Merge branch 'master' into eslint-strict
ndelangen May 31, 2017
9d38bf8
Mostly re-applied changes
ndelangen May 31, 2017
99e95a1
FIX linting
ndelangen May 31, 2017
49bb8ea
Merge branch 'master' into eslint-strict
ndelangen Jun 1, 2017
bf4219e
ADD lint-staged
ndelangen Jun 1, 2017
572d677
Merge branch 'master' into eslint-strict
shilman Jun 3, 2017
da961dc
FIX linting
ndelangen Jun 3, 2017
47eaac1
FIX linting
ndelangen Jun 3, 2017
7b5f88d
Set npm needed for project to lower then 5.0.0
ndelangen Jun 3, 2017
81b4cb8
FIX unit tests snapshots && FIX linting
ndelangen Jun 3, 2017
35f20df
FIX actions addon register
ndelangen Jun 4, 2017
8fef4bb
FIX linting
ndelangen Jun 4, 2017
6f486c5
FIX eslint cache location
ndelangen Jun 5, 2017
e40ef62
Merge branch 'master' into eslint-strict
ndelangen Jun 5, 2017
baecbf7
FIX after merge
ndelangen Jun 5, 2017
6c83d97
ADD eslint config for examples inside markdown
ndelangen Jun 6, 2017
04a0551
FIX changelog markdown
ndelangen Jun 6, 2017
3d87b27
FIX linting && ADD globals to makrdown code examples lint config
ndelangen Jun 6, 2017
dfabb18
FIX linting
ndelangen Jun 6, 2017
0ecb1bf
Add missing import
shilman Jun 6, 2017
7db3cc0
ADD linting on some rc files, CHANGe to js rc for remark
ndelangen Jun 6, 2017
d75bcb8
FIX linting
ndelangen Jun 6, 2017
e4e639e
FIX linting
ndelangen Jun 6, 2017
921daab
ADD eslint config for .json files && FIX linting
ndelangen Jun 6, 2017
7765c45
Merge branch 'master' into eslint-strict
ndelangen Jun 6, 2017
28a4b32
CHANGE all package.jsons so they are uniformly sorted
ndelangen Jun 6, 2017
d1aa2ed
FIX docs
ndelangen Jun 6, 2017
ae5dae9
CHANGE path to markdown code example eslint config to relative path
ndelangen Jun 6, 2017
432c371
Merge branch 'master' into eslint-strict
ndelangen Jun 6, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ dist
build
coverage
node_modules
**/example/**
**/demo/**
docs/public
52 changes: 52 additions & 0 deletions .eslintrc-markdown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const error = 2;
const warn = 1;
const ignore = 0;

module.exports = {
root: true,
extends: [
'eslint-config-airbnb',
'plugin:jest/recommended',
'prettier',
],
plugins: [
'prettier',
'jest',
'react',
],
parser: 'babel-eslint',
parserOptions: {
sourceType: 'module',
},
env: {
es6: true,
node: true,
'jest/globals': true,
},
rules: {
strict: [error, 'never'],
'prettier/prettier': [warn, {
printWidth: 100,
tabWidth: 2,
bracketSpacing: true,
trailingComma: 'es5',
singleQuote: true,
}],
quotes: [warn, 'single'],
'no-unused-vars': ignore,
'class-methods-use-this': ignore,
'arrow-parens': [warn, 'as-needed'],
'space-before-function-paren': ignore,
'import/no-unresolved': ignore,
'import/extensions': ignore,
'import/no-extraneous-dependencies': ignore,
'import/prefer-default-export': ignore,
'react/jsx-wrap-multilines': ignore,
'react/jsx-uses-react': error,
'react/jsx-uses-vars': error,
'react/react-in-jsx-scope': error,
'react/jsx-filename-extension': ignore,
'jsx-a11y/accessible-emoji': ignore,
'react/no-unescaped-entities': ignore,
},
}
45 changes: 40 additions & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
const error = 2;
const warn = 1;
const ignore = 0;

module.exports = {
root: true,
extends: [
'./node_modules/eslint-config-airbnb-base/rules/es6.js',
'eslint-config-airbnb',
'plugin:jest/recommended',
'prettier',
],
plugins: [
'prettier',
'jest',
'react',
],
parser: 'babel-eslint',
parserOptions: {
Expand All @@ -13,17 +21,44 @@ module.exports = {
env: {
es6: true,
node: true,
'jest/globals': true,
},
rules: {
strict: 0,
'prettier/prettier': ['warn', {
strict: [error, 'never'],
'prettier/prettier': [warn, {
printWidth: 100,
tabWidth: 2,
bracketSpacing: true,
trailingComma: 'es5',
singleQuote: true,
}],
quotes: ['warn', 'single'],
'arrow-parens': ['warn', 'as-needed'],
quotes: [warn, 'single'],
'class-methods-use-this': ignore,
'arrow-parens': [warn, 'as-needed'],
'space-before-function-paren': ignore,
'import/no-unresolved': warn,
'import/extensions': [warn, {
js: 'never',
json: 'always',
}],
'import/no-extraneous-dependencies': [warn, {
devDependencies: [
'**/*.test.js',
'**/scripts/*.js',
'**/stories/*.js',
'**/__tests__/*.js'
],
peerDependencies: true
}],
'import/prefer-default-export': ignore,
'react/jsx-wrap-multilines': ignore,
'react/jsx-uses-react': error,
'react/jsx-uses-vars': error,
'react/react-in-jsx-scope': error,
'react/jsx-filename-extension': [warn, {
extensions: ['.js', '.jsx']
}],
'jsx-a11y/accessible-emoji': ignore,
'react/no-unescaped-entities': ignore,
},
}
3 changes: 2 additions & 1 deletion .remarkrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
["remark-lint-code", {"js": {
"module": "node_modules/remark-lint-code-eslint",
"options": {
"fix": true
"fix": true,
"configFile": "/Users/dev/Projects/GitHub/storybook/react-storybook/.eslintrc-markdown.js"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix this

}
}}],
["remark-toc", {
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ We welcome contributions to Storybook!
> boolean check if code conforms to linting rules - uses remark & eslint

- `npm run lint:js` - will check js
- `npm run lint:markdown` - will check markdown + code samples
- `npm run lint:md` - will check markdown + code samples

- `npm run lint:js -- --fix` - will automatically fix js
- `npm run lint:markdown -- -o` - will automatically fix markdown
- `npm run lint:md -- -o` - will automatically fix markdown

#### `npm run test`

Expand Down
1 change: 1 addition & 0 deletions addons/actions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ This addon works with Storybook for:
## Getting Started

Install:

```sh
npm i -D @storybook/addon-actions
```
Expand Down
18 changes: 11 additions & 7 deletions addons/actions/src/components/ActionLogger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import style from './style';

class ActionLogger extends Component {
componentDidUpdate() {
const latest = this.refs.latest;
const latest = this.ref.latest;
if (latest) {
const borderLeft = style.action.borderLeft;
latest.style.borderLeft = 'solid 5px #aaa';
Expand All @@ -15,8 +15,12 @@ class ActionLogger extends Component {
}
}

getActionData() {
return this.props.actions.map((action, i) => this.renderAction(action, i));
}

renderAction(action, i) {
const ref = i ? '' : 'latest';
const ref = () => (this.ref = i ? '' : 'latest');
const counter = <div style={style.counter}>{action.count}</div>;
return (
<div ref={ref} key={action.id} style={style.action}>
Expand All @@ -34,10 +38,6 @@ class ActionLogger extends Component {
);
}

getActionData() {
return this.props.actions.map((action, i) => this.renderAction(action, i));
}

render() {
return (
<div style={style.wrapper}>
Expand All @@ -50,7 +50,11 @@ class ActionLogger extends Component {

ActionLogger.propTypes = {
onClear: PropTypes.func,
actions: PropTypes.array,
actions: PropTypes.array, // eslint-disable-line react/forbid-prop-types
};
ActionLogger.defaultProps = {
onClear: () => {},
actions: [],
};

export default ActionLogger;
33 changes: 22 additions & 11 deletions addons/actions/src/containers/ActionLogger/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/* eslint-disable no-underscore-dangle */

import React from 'react';
import PropTypes from 'prop-types';
import deepEqual from 'deep-equal';

import ActionLoggerComponent from '../../components/ActionLogger/';
import { EVENT_ID } from '../../';

Expand All @@ -10,14 +14,22 @@ export default class ActionLogger extends React.Component {
this._actionListener = action => this.addAction(action);
}

componentDidMount() {
this.props.channel.on(EVENT_ID, this._actionListener);
}

componentWillUnmount() {
this.props.channel.removeListener(EVENT_ID, this._actionListener);
}

addAction(action) {
action.data.args = action.data.args.map(arg => JSON.parse(arg));
action.data.args = action.data.args.map(arg => JSON.parse(arg)); // eslint-disable-line
const actions = [...this.state.actions];
const previous = actions.length && actions[0];
if (previous && deepEqual(previous.data, action.data, { strict: true })) {
previous.count++;
previous.count++; // eslint-disable-line
} else {
action.count = 1;
action.count = 1; // eslint-disable-line
actions.unshift(action);
}
this.setState({ actions });
Expand All @@ -27,14 +39,6 @@ export default class ActionLogger extends React.Component {
this.setState({ actions: [] });
}

componentDidMount() {
this.props.channel.on(EVENT_ID, this._actionListener);
}

componentWillUnmount() {
this.props.channel.removeListener(EVENT_ID, this._actionListener);
}

render() {
const props = {
actions: this.state.actions,
Expand All @@ -43,3 +47,10 @@ export default class ActionLogger extends React.Component {
return <ActionLoggerComponent {...props} />;
}
}

ActionLogger.propTypes = {
channel: PropTypes.object, // eslint-disable-line react/forbid-prop-types
};
ActionLogger.defaultProps = {
channel: {},
};
2 changes: 1 addition & 1 deletion addons/actions/src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// addons, panels and events get unique names using a prefix
export const ADDON_ID = 'storybook/addon-actions';
export const ADDON_ID = 'storybook/actions';
export const PANEL_ID = `${ADDON_ID}/actions-panel`;
export const EVENT_ID = `${ADDON_ID}/action-event`;

Expand Down
2 changes: 1 addition & 1 deletion addons/actions/src/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ActionLogger from './containers/ActionLogger';
import { ADDON_ID, PANEL_ID } from './';

export function register() {
addons.register(ADDON_ID, api => {
addons.register(ADDON_ID, () => {
const channel = addons.getChannel();
addons.addPanel(PANEL_ID, {
title: 'Action Logger',
Expand Down
6 changes: 6 additions & 0 deletions addons/actions/src/preview.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable no-underscore-dangle */

import addons from '@storybook/addons';
import stringify from 'json-stringify-safe';
import { EVENT_ID } from './';
Expand All @@ -10,6 +12,7 @@ function _format(arg) {
}

export function action(name) {
// eslint-disable-next-line no-unused-vars, func-names
const handler = function(..._args) {
const args = Array.from(_args).map(_format);
const channel = addons.getChannel();
Expand All @@ -27,13 +30,16 @@ export function action(name) {
//
// Ref: https://bocoup.com/weblog/whats-in-a-function-name
const fnName = name ? name.replace(/\W+/g, '_') : 'action';
// eslint-disable-next-line no-eval
const named = eval(`(function ${fnName}() { return handler.apply(this, arguments) })`);
return named;
}

export function decorateAction(decorators) {
// eslint-disable-next-line no-unused-vars, func-names
return function(name) {
const callAction = action(name);
// eslint-disable-next-line no-unused-vars, func-names
return function(..._args) {
const decorated = decorators.reduce((args, fn) => fn(args), _args);
callAction(...decorated);
Expand Down
5 changes: 4 additions & 1 deletion addons/centered/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
"prepublish": "node ../../scripts/prepublish.js"
},
"author": "Muhammed Thanish <[email protected]>",
"license": "MIT"
"license": "MIT",
"peerDependencies": {
"react": "*"
}
}
1 change: 1 addition & 0 deletions addons/comments/manager.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
const manager = require('./dist/manager');

manager.init();
1 change: 1 addition & 0 deletions addons/comments/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"babel-runtime": "^6.23.0",
"deep-equal": "^1.0.1",
"events": "^1.1.1",
"global": "^4.3.2",
"insert-css": "^1.0.0",
"marked": "^0.3.6",
"moment": "^2.18.1",
Expand Down
1 change: 1 addition & 0 deletions addons/comments/preview.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
const preview = require('./dist/preview');

preview.init();
12 changes: 8 additions & 4 deletions addons/comments/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@ const buttonStyles = {
padding: '3px 10px',
};

const Button = ({ children, onClick, style = {} }) => (
const Button = ({ children, onClick, style = {} }) =>
<button style={{ ...buttonStyles, ...style }} onClick={onClick}>
{children}
</button>
);
</button>;

Button.defaultProps = {
onClick: () => {},
style: {},
};

Button.propTypes = {
children: PropTypes.string.isRequired,
onClick: PropTypes.func,
style: PropTypes.object,
style: PropTypes.object, // eslint-disable-line react/forbid-prop-types
};

export default Button;
Loading