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 🚑 #1000

Closed
wants to merge 42 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 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
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,3 +2,5 @@ dist
build
coverage
node_modules
**/example/**
**/demo/**
35 changes: 33 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
const error = 2;
const warn = 1;
const ignore = 0;

module.exports = {
extends: [
'./node_modules/eslint-config-airbnb-base/rules/es6.js',
'@ndelangen/eslint-config-airbnb',
'prettier',
'plugin:jest/recommended'
],
plugins: [
'prettier',
'jest',
'react',
],
parser: 'babel-eslint',
parserOptions: {
Expand All @@ -12,9 +20,10 @@ module.exports = {
env: {
es6: true,
node: true,
'jest/globals': true,
},
rules: {
strict: 0,
strict: [error, 'never'],
'prettier/prettier': ['warn', {
printWidth: 100,
tabWidth: 2,
Expand All @@ -23,6 +32,28 @@ module.exports = {
singleQuote: true,
}],
quotes: ['warn', 'single'],
'class-methods-use-this': ignore,
'arrow-parens': ['warn', 'as-needed'],
'space-before-function-paren': ignore,
'import/no-unresolved': warn,
'import/extentions': warn,
'import/no-extraneous-dependencies': [warn, {
devDependencies: [
'**/*.test.js',
'**/scripts/*.js',
'**/stories/*.js',
'**/__tests__/*.js'
],
peerDependencies: true
}],
'import/prefer-default-export': 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,
},
}
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ before_install: ./scripts/travis/before_install.sh
after_success: ./scripts/travis/after_success.sh
script:
- npm run bootstrap
- npm run examples
- npm run lint
- npm run test -- --coverage
- npm run coverage
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)) {
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: {},
};
4 changes: 2 additions & 2 deletions addons/actions/src/manager.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react';
import addons from '@storybook/addons';
import ActionLogger from './containers/ActionLogger';
import { ADDON_ID, PANEL_ID } from './';
import { PANEL_ID } from './';

export function register() {
addons.register(ADDON_ID, api => {
addons.register(() => {
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
4 changes: 3 additions & 1 deletion addons/centered/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@
"babelify"
]
},
"devDependencies": {}
"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 @@ -26,6 +26,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();
7 changes: 6 additions & 1 deletion addons/comments/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@ const Button = ({ children, onClick, style = {} }) => (
</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;
16 changes: 10 additions & 6 deletions addons/comments/src/manager/components/CommentForm/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { window } from 'global';
import Textarea from 'react-textarea-autosize';
import marked from 'marked';
import style from './style';

const renderer = new marked.Renderer();
renderer.heading = function(text) {
return text;
};
renderer.heading = text => text;

marked.setOptions({
renderer,
Expand Down Expand Up @@ -43,8 +42,8 @@ export default class CommentForm extends Component {
}

openLogin() {
const signInUrl = `https://hub.getstorybook.io/sign-in?redirectUrl=${encodeURIComponent(location.href)}`;
location.href = signInUrl;
const signInUrl = `https://hub.getstorybook.io/sign-in?redirectUrl=${encodeURIComponent(window.location.href)}`;
window.location.href = signInUrl;
}

handleKeyDown(e) {
Expand All @@ -58,7 +57,7 @@ export default class CommentForm extends Component {
if (!this.props.user) {
return (
<div style={style.wrapper}>
<Textarea style={style.input} disabled={true} />
<Textarea style={style.input} disabled />
<button style={style.submitButton} onClick={() => this.openLogin()}>
Sign in with Storybook Hub
</button>
Expand All @@ -84,6 +83,11 @@ export default class CommentForm extends Component {
}
}

CommentForm.defaultProps = {
user: null,
addComment: () => {},
};
CommentForm.propTypes = {
user: PropTypes.object, // eslint-disable-line react/forbid-prop-types
addComment: PropTypes.func,
};
18 changes: 15 additions & 3 deletions addons/comments/src/manager/components/CommentItem/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { window } from 'global';
import moment from 'moment';
import renderHTML from 'react-render-html';
import insertCss from 'insert-css';
Expand All @@ -26,15 +27,15 @@ export default class CommentItem extends Component {
}

deleteComment() {
const confirmDelete = confirm('Are you sure you want to delete this comment?');
const confirmDelete = window.confirm('Are you sure you want to delete this comment?');
if (confirmDelete === true) {
this.props.deleteComment();
}
}

renderDelete() {
return (
<a href="#" style={style.commentDelete} onClick={this.deleteComment}>
<a style={style.commentDelete} onClick={this.deleteComment} role="button" tabIndex="0">
delete
</a>
);
Expand Down Expand Up @@ -69,8 +70,19 @@ export default class CommentItem extends Component {
}
}

CommentItem.defaultProps = {
comment: {},
deleteComment: () => {},
ownComment: false,
};

CommentItem.propTypes = {
deleteComment: PropTypes.func,
comment: PropTypes.object,
comment: PropTypes.shape({
user: PropTypes.object,
text: PropTypes.string,
time: PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Date)]),
loading: PropTypes.bool,
}),
ownComment: PropTypes.bool,
};
16 changes: 12 additions & 4 deletions addons/comments/src/manager/components/CommentList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ export default class CommentList extends Component {
}}
style={style.wrapper}
>
{comments.map((comment, idx) => (
{comments.map(comment => (
<CommentItem
key={`comment_${idx}`}
key={comment.id}
comment={comment}
ownComment={comment.userId === (this.props.user && this.props.user.id)}
deleteComment={() => this.props.deleteComment(comment.id)}
Expand All @@ -50,8 +50,16 @@ export default class CommentList extends Component {
}
}

CommentList.defaultProps = {
comments: [],
user: null,
deleteComment: () => {},
};

CommentList.propTypes = {
comments: PropTypes.array,
user: PropTypes.object,
comments: PropTypes.arrayOf(PropTypes.object),
user: PropTypes.shape({
id: PropTypes.number,
}),
deleteComment: PropTypes.func,
};
Loading