From f54e7ca7c8c4a413fc0552b427b9729c82d34207 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Thu, 28 Jan 2016 08:30:49 -0600 Subject: [PATCH 1/4] Framework: Enable wpcalypso ESLint plugin for lodash import --- .eslintrc.js | 7 +++++-- package.json | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 9bb38a2f4eb19..0c8e686a9961c 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -12,7 +12,8 @@ module.exports = { 'modules': true }, 'plugins': [ - 'eslint-plugin-react' + 'eslint-plugin-react', + 'eslint-plugin-wpcalypso' ], 'rules': { 'brace-style': [ 1, '1tbs' ], @@ -89,6 +90,8 @@ module.exports = { 'valid-jsdoc': [ 1, { 'requireReturn': false } ], // Common top-of-file requires, expressions between external, interal 'vars-on-top': 1, - 'yoda': 0 + 'yoda': 0, + // Custom rules + "wpcalypso/no-lodash-import": 2 } }; diff --git a/package.json b/package.json index 504e6e53697a1..92e43e2877224 100644 --- a/package.json +++ b/package.json @@ -129,6 +129,7 @@ "esformatter-special-bangs": "1.0.1", "eslint": "1.10.3", "eslint-plugin-react": "3.11.3", + "eslint-plugin-wpcalypso": "1.0.0", "jsdom": "7.2.0", "localStorage": "1.0.2", "lodash-deep": "1.5.3", From f587728124c49be9e5b33fd2da9ffe76035ccd90 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Thu, 28 Jan 2016 08:31:29 -0600 Subject: [PATCH 2/4] Framework: Fix ESLint issues with Lodash import --- client/lib/user/support-user-interop.js | 4 ++-- client/my-sites/exporter/index.jsx | 2 +- client/my-sites/exporter/spinner-button.jsx | 2 +- client/state/notices/actions.js | 7 +++++-- server/i18nlint/i18nlint.js | 4 ++-- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/client/lib/user/support-user-interop.js b/client/lib/user/support-user-interop.js index 01f9e0bbad013..07dcc67aa86ea 100644 --- a/client/lib/user/support-user-interop.js +++ b/client/lib/user/support-user-interop.js @@ -1,7 +1,7 @@ /** * External dependencies */ -import { compose } from 'lodash'; +import compose from 'lodash/function/compose'; /** * Internal dependencies @@ -43,7 +43,7 @@ export default function( reduxStore ) { // update the wpcom API interceptor accordingly. reduxStore.subscribe( () => { const state = reduxStore.getState(); - + if ( wpcom.setSupportUserToken( getSupportUser( state ), getSupportToken( state ) ) ) { onTokenChange(); } diff --git a/client/my-sites/exporter/index.jsx b/client/my-sites/exporter/index.jsx index 0283ac0b94c30..072d568179beb 100644 --- a/client/my-sites/exporter/index.jsx +++ b/client/my-sites/exporter/index.jsx @@ -2,7 +2,7 @@ * External dependencies */ import { connect } from 'react-redux'; -import { compose } from 'lodash'; +import compose from 'lodash/function/compose'; /** * Internal dependencies diff --git a/client/my-sites/exporter/spinner-button.jsx b/client/my-sites/exporter/spinner-button.jsx index 289ba86f645e9..12279fe887b99 100644 --- a/client/my-sites/exporter/spinner-button.jsx +++ b/client/my-sites/exporter/spinner-button.jsx @@ -2,7 +2,7 @@ * External dependencies */ import React, { PropTypes } from 'react'; -import { omit } from 'lodash'; +import omit from 'lodash/object/omit'; /** * Internal dependencies diff --git a/client/state/notices/actions.js b/client/state/notices/actions.js index df48a23f70bee..34b645f13c8ab 100644 --- a/client/state/notices/actions.js +++ b/client/state/notices/actions.js @@ -1,3 +1,8 @@ +/** + * External dependencies + */ +import uniqueId from 'lodash/utility/uniqueId'; + /** * Internal dependencies */ @@ -7,8 +12,6 @@ import { SET_ROUTE } from 'state/action-types'; -import { uniqueId } from 'lodash'; - export function removeNotice( noticeId ) { return { noticeId: noticeId, diff --git a/server/i18nlint/i18nlint.js b/server/i18nlint/i18nlint.js index 635dfcaf50f5d..490972027b2cc 100644 --- a/server/i18nlint/i18nlint.js +++ b/server/i18nlint/i18nlint.js @@ -10,8 +10,8 @@ var fs = require( 'fs' ), preProcessXGettextJSMatch = require( '../i18n/preprocess-xgettextjs-match.js' ), SourceMapConsumer = require( 'source-map' ).SourceMapConsumer, tokenize = require( '../../client/lib/interpolate-components/tokenize.js' ), - contains = require( 'lodash' ).contains, - flow = require( 'lodash' ).flow; + contains = require( 'lodash/collection/contains' ), + flow = require( 'lodash/function/flow' ); /* * Module variables From b41af2f2125fbd481dd087d2f2bbe4732ec53a07 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Tue, 2 Feb 2016 18:10:01 -0500 Subject: [PATCH 3/4] Framework: Update shrinkwrap to include eslint-plugin-wpcalypso --- npm-shrinkwrap.json | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 0d54597cec5d8..e01f9cb1dbaf4 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -13321,6 +13321,14 @@ } } } + }, + "eslint-plugin-wpcalypso": { + "version": "1.0.0", + "dependencies": { + "requireindex": { + "version": "1.1.0" + } + } } } } From 761b5b4cac2cc1f7917967dde972f46e6b401a08 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Mon, 8 Feb 2016 10:53:33 -0500 Subject: [PATCH 4/4] Docs: Update ESLint usage to account for wpcalypso plugin --- docs/coding-guidelines/javascript.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/coding-guidelines/javascript.md b/docs/coding-guidelines/javascript.md index 98ae68f2fcd23..a4ec358783d2b 100644 --- a/docs/coding-guidelines/javascript.md +++ b/docs/coding-guidelines/javascript.md @@ -979,7 +979,7 @@ More about: ## ESLint -To help encourages folks to follow the coding standards, there is a [ESLint](http://eslint.org/) configuration file ```.eslintrc``` that configures ESLint to detect code that doesn't follow the guidelines. ESLint also catches basic syntax errors, and natively supports both ES6 and JSX. It can be extended by plugins, such as [eslint-plugin-react](https://github.com/yannickcr/eslint-plugin-react), which we use in our configuration. +To help encourages folks to follow the coding standards, there is a [ESLint](http://eslint.org/) configuration file ```.eslintrc``` that configures ESLint to detect code that doesn't follow the guidelines. ESLint also catches basic syntax errors, and natively supports both ES6 and JSX. It can be extended by plugins, such as [`eslint-plugin-wpcalypso`](https://github.com/yannickcr/eslint-plugin-wpcalypso), which we use in our configuration. There are [integrations](http://eslint.org/docs/user-guide/integrations) for many editors that will automatically detect the configuration file and run the checks. @@ -1044,7 +1044,7 @@ If you are using Sublime Text, you can use the `SublimeLinter-eslint` plugin to Before following these instructions, you'll want to globally install ESLint and related dependencies by running the following command in your terminal: ```bash -npm install -g eslint eslint-plugin-react babel-eslint +npm install -g eslint eslint-plugin-wpcalypso eslint-plugin-react babel-eslint ``` #### Identifying Spaces with Sublime Text