diff --git a/.eslintrc b/.eslintrc index 4a87446a26d5..98472c32f2a2 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,10 +1,19 @@ { "extends": "airbnb", "rules": { - "react/jsx-no-bind": 0, - "react/prefer-stateless-function": 0, + # We use _ to define private variables and methods in clases + "no-underscore-dangle": 0, + # This seems to be buggy we don't want eslint to check this + "import/no-extraneous-dependencies": 0, + # This is a depricated rule. So we turned off it. + "react/require-extension": 0, + # We can write JSX in anyfile we want. + "react/jsx-filename-extension": 0, + # We don't like this rule. "arrow-body-style": 0, + # We don't like this rule. We write arrow functions only when we needed. "prefer-arrow-callback": 0, + # We don't need to write function names always. "func-names": 0 }, "parserOptions": { @@ -12,5 +21,5 @@ "ecmaFeatures": { "experimentalObjectRestSpread": true } - } + }, } diff --git a/dist/client/manager/index.js b/dist/client/manager/index.js index 418ecdd8773b..5e5c9e65029f 100644 --- a/dist/client/manager/index.js +++ b/dist/client/manager/index.js @@ -10,5 +10,7 @@ var _provider2 = _interopRequireDefault(_provider); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +/* global document */ + var rootEl = document.getElementById('root'); (0, _storybookUi2.default)(rootEl, new _provider2.default()); \ No newline at end of file diff --git a/dist/client/manager/provider.js b/dist/client/manager/provider.js index 19ebc99ce694..aed3637239cd 100644 --- a/dist/client/manager/provider.js +++ b/dist/client/manager/provider.js @@ -56,6 +56,8 @@ var _preview2 = _interopRequireDefault(_preview); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +/* global location */ + var ReactProvider = function (_Provider) { (0, _inherits3.default)(ReactProvider, _Provider); diff --git a/dist/client/preview/client_api.js b/dist/client/preview/client_api.js index 25fffb0b2509..0df644972b2c 100644 --- a/dist/client/preview/client_api.js +++ b/dist/client/preview/client_api.js @@ -8,6 +8,10 @@ var _toConsumableArray2 = require("babel-runtime/helpers/toConsumableArray"); var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2); +var _keys = require("babel-runtime/core-js/object/keys"); + +var _keys2 = _interopRequireDefault(_keys); + var _extends2 = require("babel-runtime/helpers/extends"); var _extends3 = _interopRequireDefault(_extends2); @@ -68,21 +72,17 @@ var ClientApi = function () { }; // apply addons - for (var name in this._addons) { - if (this._addons.hasOwnProperty(name)) { - (function () { - var addon = _this._addons[name]; - api[name] = function () { - for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { - args[_key] = arguments[_key]; - } - - addon.apply(api, args); - return api; - }; - })(); - } - } + (0, _keys2.default)(this._addons).forEach(function (name) { + var addon = _this._addons[name]; + api[name] = function () { + for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + + addon.apply(api, args); + return api; + }; + }); api.add = function (storyName, getStory) { // Wrap the getStory function with each decorator. The first diff --git a/dist/client/preview/error_display.js b/dist/client/preview/error_display.js index 03e7a8bbb706..f95c22f6f083 100644 --- a/dist/client/preview/error_display.js +++ b/dist/client/preview/error_display.js @@ -12,7 +12,10 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de var mainStyle = { position: 'fixed', - top: 0, bottom: 0, left: 0, right: 0, + top: 0, + bottom: 0, + left: 0, + right: 0, padding: 20, backgroundColor: 'rgb(187, 49, 49)', color: '#FFF', diff --git a/dist/client/preview/index.js b/dist/client/preview/index.js index c2ca95d52540..c796430e85b4 100644 --- a/dist/client/preview/index.js +++ b/dist/client/preview/index.js @@ -9,6 +9,20 @@ var _assign = require('babel-runtime/core-js/object/assign'); var _assign2 = _interopRequireDefault(_assign); +var _redux = require('redux'); + +var _storybookAddons = require('@kadira/storybook-addons'); + +var _storybookAddons2 = _interopRequireDefault(_storybookAddons); + +var _storybookChannelPagebus = require('@kadira/storybook-channel-pagebus'); + +var _storybookChannelPagebus2 = _interopRequireDefault(_storybookChannelPagebus); + +var _qs = require('qs'); + +var _qs2 = _interopRequireDefault(_qs); + var _story_store = require('./story_store'); var _story_store2 = _interopRequireDefault(_story_store); @@ -25,26 +39,12 @@ var _render = require('./render'); var _render2 = _interopRequireDefault(_render); -var _qs = require('qs'); - -var _qs2 = _interopRequireDefault(_qs); - var _init = require('./init'); var _init2 = _interopRequireDefault(_init); -var _storybookChannelPagebus = require('@kadira/storybook-channel-pagebus'); - -var _storybookChannelPagebus2 = _interopRequireDefault(_storybookChannelPagebus); - var _actions = require('./actions'); -var _storybookAddons = require('@kadira/storybook-addons'); - -var _storybookAddons2 = _interopRequireDefault(_storybookAddons); - -var _redux = require('redux'); - var _reducer = require('./reducer'); var _reducer2 = _interopRequireDefault(_reducer); @@ -52,7 +52,7 @@ var _reducer2 = _interopRequireDefault(_reducer); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } // check whether we're running on node/browser -var isBrowser = typeof window !== 'undefined'; +var isBrowser = typeof window !== 'undefined'; /* global window */ var storyStore = new _story_store2.default(); var reduxStore = (0, _redux.createStore)(_reducer2.default); diff --git a/dist/client/preview/init.js b/dist/client/preview/init.js index bdfdf6d040b9..1903e0ea352d 100644 --- a/dist/client/preview/init.js +++ b/dist/client/preview/init.js @@ -24,10 +24,10 @@ exports.default = function (context) { }; }; -var _actions = require('./actions'); - var _key_events = require('@kadira/storybook-ui/dist/libs/key_events'); var _key_events2 = _interopRequireDefault(_key_events); +var _actions = require('./actions'); + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } \ No newline at end of file diff --git a/dist/client/preview/render.js b/dist/client/preview/render.js index 554c7a075963..5156b744c392 100644 --- a/dist/client/preview/render.js +++ b/dist/client/preview/render.js @@ -22,7 +22,7 @@ var _error_display2 = _interopRequireDefault(_error_display); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } // check whether we're running on node/browser -var isBrowser = typeof window !== 'undefined'; +var isBrowser = typeof window !== 'undefined'; /* global document */ var rootEl = null; var previousKind = ''; @@ -58,7 +58,8 @@ function renderMain(data, storyStore) { var story = storyStore.getStory(selectedKind, selectedStory); if (!story) { - return _reactDom2.default.render(noPreview, rootEl); + _reactDom2.default.render(noPreview, rootEl); + return null; } // Unmount the previous story only if selectedKind or selectedStory has changed. @@ -81,7 +82,8 @@ function renderMain(data, storyStore) { }; try { - return _reactDom2.default.render(story(context), rootEl); + _reactDom2.default.render(story(context), rootEl); + return null; } catch (ex) { return renderError(ex); } diff --git a/dist/server/build.js b/dist/server/build.js old mode 100644 new mode 100755 diff --git a/dist/server/config.js b/dist/server/config.js index f26193f44c96..f8fde42cf218 100644 --- a/dist/server/config.js +++ b/dist/server/config.js @@ -99,7 +99,7 @@ var _json2 = _interopRequireDefault(_json); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } // avoid ESLint errors -var logger = console; +var logger = console; /* eslint global-require: 0 */ function removeReactHmre(presets) { var index = presets.indexOf('react-hmre'); diff --git a/dist/server/config/error_enhancements.js b/dist/server/config/error_enhancements.js index b1b95697ffb2..bf917c4edaa4 100644 --- a/dist/server/config/error_enhancements.js +++ b/dist/server/config/error_enhancements.js @@ -1,5 +1,8 @@ 'use strict'; +/* eslint global-require: 0 */ +/* global navigator */ + var isChrome = function isChrome() { return navigator.userAgent.toLowerCase().indexOf('chrome') > -1; }; diff --git a/dist/server/config/webpack.config.js b/dist/server/config/webpack.config.js index 63408a4b33b1..2c8951854eaa 100644 --- a/dist/server/config/webpack.config.js +++ b/dist/server/config/webpack.config.js @@ -18,6 +18,10 @@ var _caseSensitivePathsWebpackPlugin2 = _interopRequireDefault(_caseSensitivePat var _utils = require('./utils'); +var _babel = require('./babel.js'); + +var _babel2 = _interopRequireDefault(_babel); + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var config = { @@ -36,7 +40,7 @@ var config = { loaders: [{ test: /\.jsx?$/, loader: require.resolve('babel-loader'), - query: require('./babel.js'), + query: _babel2.default, include: _utils.includePaths, exclude: _utils.excludePaths }] diff --git a/dist/server/config/webpack.config.prod.js b/dist/server/config/webpack.config.prod.js index e736e5ffa755..42e3126ff5f9 100644 --- a/dist/server/config/webpack.config.prod.js +++ b/dist/server/config/webpack.config.prod.js @@ -14,6 +14,10 @@ var _webpack2 = _interopRequireDefault(_webpack); var _utils = require('./utils'); +var _babelProd = require('./babel.prod.js'); + +var _babelProd2 = _interopRequireDefault(_babelProd); + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var entries = { @@ -51,7 +55,7 @@ var config = { loaders: [{ test: /\.jsx?$/, loader: require.resolve('babel-loader'), - query: require('./babel.prod.js'), + query: _babelProd2.default, include: _utils.includePaths, exclude: _utils.excludePaths }] diff --git a/dist/server/index.js b/dist/server/index.js index c89b184d66f9..28a72d954e39 100755 --- a/dist/server/index.js +++ b/dist/server/index.js @@ -1,6 +1,10 @@ #!/usr/bin/env node 'use strict'; +var _middleware = require('@kadira/storybook-database-local/dist/server/middleware'); + +var _middleware2 = _interopRequireDefault(_middleware); + var _express = require('express'); var _express2 = _interopRequireDefault(_express); @@ -17,11 +21,7 @@ var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs); -var _middleware = require('./middleware'); - -var _middleware2 = _interopRequireDefault(_middleware); - -var _middleware3 = require('@kadira/storybook-database-local/dist/server/middleware'); +var _middleware3 = require('./middleware'); var _middleware4 = _interopRequireDefault(_middleware3); @@ -83,13 +83,13 @@ if (_commander2.default.staticDir) { // Build the webpack configuration using the `baseConfig` // custom `.babelrc` file and `webpack.config.js` files var configDir = _commander2.default.configDir || './.storybook'; -app.use((0, _middleware2.default)(configDir)); +app.use((0, _middleware4.default)(configDir)); // The addon database service is disabled by default for now // It should be enabled with the --enable-db for dev server if (_commander2.default.enableDb) { var dbPath = _commander2.default.dbPath || _path2.default.resolve(configDir, 'addon-db.json'); - app.use('/db', (0, _middleware4.default)(dbPath)); + app.use('/db', (0, _middleware2.default)(dbPath)); } app.listen.apply(app, listenAddr.concat([function (error) { diff --git a/dist/server/track_usage.js b/dist/server/track_usage.js index c3b122301367..514d95d9e8bd 100644 --- a/dist/server/track_usage.js +++ b/dist/server/track_usage.js @@ -21,7 +21,9 @@ var _request2 = _interopRequireDefault(_request); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } -var logger = console; // ### WHAT? +var logger = console; /* eslint global-require: 0 */ + +// ### WHAT? // // We will track anonymous usage of how you use storybook. // We don't want any personal information. diff --git a/package.json b/package.json index 42140ee8420f..0bbbae80d3d0 100644 --- a/package.json +++ b/package.json @@ -47,20 +47,20 @@ "case-sensitive-paths-webpack-plugin": "^1.1.2", "commander": "^2.9.0", "configstore": "^2.0.0", - "css-loader": "0.23.1", + "css-loader": "0.24.0", "express": "^4.13.3", "file-loader": "^0.9.0", "json-loader": "^0.5.4", "json-stringify-safe": "^5.0.1", "json5": "^0.5.0", "lodash.pick": "^4.2.0", - "postcss-loader": "0.9.1", + "postcss-loader": "0.11.1", "qs": "^6.1.0", "react-modal": "^1.2.0", "redbox-react": "^1.2.2", "redux": "^3.5.2", "request": "^2.74.0", - "shelljs": "^0.6.0", + "shelljs": "^0.7.4", "stack-source-map": "^1.0.5", "style-loader": "0.13.1", "url-loader": "^0.5.7", @@ -80,14 +80,15 @@ "chai": "^3.5.0", "deep-equal": "^1.0.1", "enzyme": "^2.2.0", - "eslint": "^2.7.0", - "eslint-config-airbnb": "^6.2.0", - "eslint-plugin-babel": "^3.1.0", - "eslint-plugin-react": "^4.2.3", + "eslint": "^3.4.0", + "eslint-config-airbnb": "^10.0.1", + "eslint-plugin-import": "^1.13.0", + "eslint-plugin-jsx-a11y": "^2.1.0", + "eslint-plugin-react": "^6.1.2", "expect": "^1.6.0", "greenkeeper-postpublish": "^1.0.1", - "jsdom": "^8.4.0", - "mocha": "^2.4.5", + "jsdom": "^9.5.0", + "mocha": "^3.0.2", "mock-fs": "^3.8.0", "nodemon": "^1.9.1", "react": "^15.0.0", diff --git a/src/client/manager/index.js b/src/client/manager/index.js index d125939f1d62..b377c72e7160 100644 --- a/src/client/manager/index.js +++ b/src/client/manager/index.js @@ -1,3 +1,5 @@ +/* global document */ + import renderStorybookUI from '@kadira/storybook-ui'; import Provider from './provider'; diff --git a/src/client/manager/provider.js b/src/client/manager/provider.js index 0b7f5812f5e2..5cc655bd4f71 100644 --- a/src/client/manager/provider.js +++ b/src/client/manager/provider.js @@ -1,3 +1,5 @@ +/* global location */ + import UUID from 'uuid'; import qs from 'qs'; import React from 'react'; diff --git a/src/client/preview/__tests__/client_api.js b/src/client/preview/__tests__/client_api.js index 65d5d05b8e14..40140a2b8bfa 100644 --- a/src/client/preview/__tests__/client_api.js +++ b/src/client/preview/__tests__/client_api.js @@ -1,6 +1,7 @@ +import { expect } from 'chai'; import ClientAPI from '../client_api'; + const { describe, it } = global; -import { expect } from 'chai'; class StoryStore { constructor() { diff --git a/src/client/preview/client_api.js b/src/client/preview/client_api.js index 2371a7ffbcf9..8f8e5f7a14c4 100644 --- a/src/client/preview/client_api.js +++ b/src/client/preview/client_api.js @@ -36,15 +36,13 @@ export default class ClientApi { }; // apply addons - for (const name in this._addons) { - if (this._addons.hasOwnProperty(name)) { - const addon = this._addons[name]; - api[name] = (...args) => { - addon.apply(api, args); - return api; - }; - } - } + Object.keys(this._addons).forEach((name) => { + const addon = this._addons[name]; + api[name] = (...args) => { + addon.apply(api, args); + return api; + }; + }); api.add = (storyName, getStory) => { // Wrap the getStory function with each decorator. The first diff --git a/src/client/preview/error_display.js b/src/client/preview/error_display.js index 457234159982..f3713637ef95 100644 --- a/src/client/preview/error_display.js +++ b/src/client/preview/error_display.js @@ -2,7 +2,10 @@ import React from 'react'; const mainStyle = { position: 'fixed', - top: 0, bottom: 0, left: 0, right: 0, + top: 0, + bottom: 0, + left: 0, + right: 0, padding: 20, backgroundColor: 'rgb(187, 49, 49)', color: '#FFF', diff --git a/src/client/preview/index.js b/src/client/preview/index.js index 8ab1c8f73f3f..db8a46ce9ec5 100644 --- a/src/client/preview/index.js +++ b/src/client/preview/index.js @@ -1,14 +1,15 @@ +/* global window */ + +import { createStore } from 'redux'; +import addons from '@kadira/storybook-addons'; +import createChannel from '@kadira/storybook-channel-pagebus'; +import qs from 'qs'; import StoryStore from './story_store'; import ClientApi from './client_api'; import ConfigApi from './config_api'; import render from './render'; -import qs from 'qs'; import init from './init'; -import createChannel from '@kadira/storybook-channel-pagebus'; import { selectStory } from './actions'; -import addons from '@kadira/storybook-addons'; - -import { createStore } from 'redux'; import reducer from './reducer'; // check whether we're running on node/browser diff --git a/src/client/preview/init.js b/src/client/preview/init.js index 8b49f36b91a8..c890e335eb2f 100644 --- a/src/client/preview/init.js +++ b/src/client/preview/init.js @@ -1,5 +1,5 @@ -import { selectStory } from './actions'; import keyEvents from '@kadira/storybook-ui/dist/libs/key_events'; +import { selectStory } from './actions'; export default function (context) { const { queryParams, reduxStore, window, channel } = context; diff --git a/src/client/preview/render.js b/src/client/preview/render.js index 4f97e7a93777..1861e6b56581 100644 --- a/src/client/preview/render.js +++ b/src/client/preview/render.js @@ -1,3 +1,5 @@ +/* global document */ + import React from 'react'; import ReactDOM from 'react-dom'; import ErrorDisplay from './error_display'; @@ -31,7 +33,8 @@ export function renderMain(data, storyStore) { const story = storyStore.getStory(selectedKind, selectedStory); if (!story) { - return ReactDOM.render(noPreview, rootEl); + ReactDOM.render(noPreview, rootEl); + return null; } // Unmount the previous story only if selectedKind or selectedStory has changed. @@ -54,7 +57,8 @@ export function renderMain(data, storyStore) { }; try { - return ReactDOM.render(story(context), rootEl); + ReactDOM.render(story(context), rootEl); + return null; } catch (ex) { return renderError(ex); } diff --git a/src/server/__tests__/utils.js b/src/server/__tests__/utils.js index 2974489336cd..f7eb52794e22 100644 --- a/src/server/__tests__/utils.js +++ b/src/server/__tests__/utils.js @@ -1,7 +1,8 @@ -const { describe, it, beforeEach, afterEach } = global; import { expect } from 'chai'; -import { getHeadHtml } from '../utils'; import mock from 'mock-fs'; +import { getHeadHtml } from '../utils'; + +const { describe, it, beforeEach, afterEach } = global; const HEAD_HTML_CONTENTS = ''; diff --git a/src/server/build.js b/src/server/build.js index 80469b4dcfb3..31d3d61b7997 100644 --- a/src/server/build.js +++ b/src/server/build.js @@ -1,7 +1,5 @@ #!/usr/bin/env node -process.env.NODE_ENV = process.env.NODE_ENV || 'production'; - import webpack from 'webpack'; import program from 'commander'; import path from 'path'; @@ -14,6 +12,8 @@ import getIndexHtml from './index.html'; import getIframeHtml from './iframe.html'; import { getHeadHtml, parseList, getEnvConfig } from './utils'; +process.env.NODE_ENV = process.env.NODE_ENV || 'production'; + // avoid ESLint errors const logger = console; diff --git a/src/server/config.js b/src/server/config.js index a8dc8fd06dea..ab5b57702180 100644 --- a/src/server/config.js +++ b/src/server/config.js @@ -1,3 +1,5 @@ +/* eslint global-require: 0 */ + import fs from 'fs'; import path from 'path'; import JSON5 from 'json5'; diff --git a/src/server/config/error_enhancements.js b/src/server/config/error_enhancements.js index 1c02c5b7a76e..7f0672f8971e 100644 --- a/src/server/config/error_enhancements.js +++ b/src/server/config/error_enhancements.js @@ -1,3 +1,6 @@ +/* eslint global-require: 0 */ +/* global navigator */ + const isChrome = function () { return navigator.userAgent.toLowerCase().indexOf('chrome') > -1; }; diff --git a/src/server/config/webpack.config.js b/src/server/config/webpack.config.js index 470e62ee535d..dea819c3d988 100644 --- a/src/server/config/webpack.config.js +++ b/src/server/config/webpack.config.js @@ -2,6 +2,7 @@ import path from 'path'; import webpack from 'webpack'; import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin'; import { OccurenceOrderPlugin, includePaths, excludePaths } from './utils'; +import babalLoaderConfig from './babel.js'; const config = { devtool: '#cheap-module-eval-source-map', @@ -31,7 +32,7 @@ const config = { { test: /\.jsx?$/, loader: require.resolve('babel-loader'), - query: require('./babel.js'), + query: babalLoaderConfig, include: includePaths, exclude: excludePaths, }, diff --git a/src/server/config/webpack.config.prod.js b/src/server/config/webpack.config.prod.js index e43b152c820d..f153fd11922a 100644 --- a/src/server/config/webpack.config.prod.js +++ b/src/server/config/webpack.config.prod.js @@ -1,6 +1,7 @@ import path from 'path'; import webpack from 'webpack'; import { OccurenceOrderPlugin, includePaths, excludePaths } from './utils'; +import babalLoaderConfig from './babel.prod.js'; const entries = { preview: [ @@ -47,7 +48,7 @@ const config = { { test: /\.jsx?$/, loader: require.resolve('babel-loader'), - query: require('./babel.prod.js'), + query: babalLoaderConfig, include: includePaths, exclude: excludePaths, }, diff --git a/src/server/index.js b/src/server/index.js index 1050d8405b46..b3e5451cf574 100755 --- a/src/server/index.js +++ b/src/server/index.js @@ -1,11 +1,11 @@ #!/usr/bin/env node +import datastore from '@kadira/storybook-database-local/dist/server/middleware'; import express from 'express'; import program from 'commander'; import path from 'path'; import fs from 'fs'; import storybook from './middleware'; -import datastore from '@kadira/storybook-database-local/dist/server/middleware'; import packageJson from '../../package.json'; import { parseList, getEnvConfig } from './utils'; import { track, dontTrack } from './track_usage'; diff --git a/src/server/track_usage.js b/src/server/track_usage.js index 48d72aa30443..96be130357b2 100644 --- a/src/server/track_usage.js +++ b/src/server/track_usage.js @@ -1,3 +1,5 @@ +/* eslint global-require: 0 */ + // ### WHAT? // // We will track anonymous usage of how you use storybook.