diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000000..1fa7e081e1 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,3 @@ +**/vendor/** +**/testBundles/** +assets/js/src/newsletter_editor/tinymce/wplink/plugin.js diff --git a/.eslintrc.es5.json b/.eslintrc.es5.json new file mode 100644 index 0000000000..46109d5199 --- /dev/null +++ b/.eslintrc.es5.json @@ -0,0 +1,100 @@ +{ + "extends": "airbnb-base/legacy", + "env": { + "amd": true, + "browser": true + }, + "parserOptions": { + "ecmaVersion": 5 + }, + "rules": { + "import/no-amd": 0, + + + + + + "comma-dangle": 0, + "space-before-function-paren": 0, + "prefer-arrow-callback": 0, + "no-undef": 0, + "key-spacing": 0, + "radix": 0, + "no-alert": 0, + "block-scoped-var": 0, + "guard-for-in": 0, + "no-prototype-builtins": 0, + "no-restricted-syntax": 0, + "newline-per-chained-call": 0, + "no-useless-concat": 0, + "no-multi-spaces": 0, + "no-nested-ternary": 0, + "semi-spacing": 0, + "no-sequences": 0, + "no-useless-return": 0, + "array-callback-return": 0, + "new-cap": 0, + "no-return-assign": 0, + "no-continue": 0, + "no-new": 0, + "no-cond-assign": 0, + "space-unary-ops": 0, + "no-redeclare": 0, + "no-console": 0, + "no-empty": 0, + "no-extra-semi": 0, + "no-useless-escape": 0, + "comma-spacing": 0, + "wrap-iife": 0, + "no-unused-expressions": 0, + "block-spacing": 0, + "computed-property-spacing": 0, + "no-plusplus": 0, + "array-bracket-spacing": 0, + "lines-around-directive": 0, + "no-unreachable": 0, + "default-case": 0, + "no-lonely-if": 0, + "space-before-blocks": 0, + "no-unneeded-ternary": 0, + "no-mixed-operators": 0, + "eqeqeq": 0, + "space-in-parens": 0, + "semi": 0, + "max-len": 0, + "no-multi-assign": 0, + "no-trailing-spaces": 0, + "global-require": 0, + "no-throw-literal": 0, + "no-extra-bind": 0, + "one-var-declaration-per-line": 0, + "consistent-return": 0, + "no-shadow": 0, + "no-underscore-dangle": 0, + "brace-style": 0, + "no-else-return": 0, + "no-use-before-define": 0, + "one-var": 0, + "camelcase": 0, + "spaced-comment": 0, + "quotes": 0, + "padded-blocks": 0, + "object-curly-spacing": 0, + "strict": 0, + "vars-on-top": 0, + "no-var": 0, + "space-infix-ops": 0, + "no-unused-vars": 0, + "object-shorthand": 0, + "new-parens": 0, + "no-param-reassign": 0, + "keyword-spacing": 0, + "eol-last": 0, + "dot-notation": 0, + "linebreak-style": 0, + "indent": 0, + "quote-props": 0, + "prefer-template": 0, + "func-names": 0 + } +} diff --git a/.eslintrc.es6.json b/.eslintrc.es6.json new file mode 100644 index 0000000000..2a66e505d9 --- /dev/null +++ b/.eslintrc.es6.json @@ -0,0 +1,83 @@ +{ + "extends": "airbnb-base", + "env": { + "amd": true, + "browser": true + }, + "parserOptions": { + "ecmaVersion": 6, + "ecmaFeatures": { + "jsx": true + } + }, + "rules": { + "import/no-amd": 0, + + + "comma-dangle": 0, + "prefer-arrow-callback": 0, + "func-names": 0, + "space-before-function-paren": 0, + "object-shorthand": 0, + "no-bitwise": 0, + "arrow-body-style": 0, + "prefer-template": 0, + "eol-last": 0, + "no-unused-vars": 0, + "no-plusplus": 0, + "semi": 0, + "keyword-spacing": 0, + "default-case": 0, + "quote-props": 0, + "indent": 0, + "prefer-const": 0, + "arrow-parens": 0, + "array-callback-return": 0, + "consistent-return": 0, + "no-unreachable": 0, + "no-extra-semi": 0, + "import/no-unresolved": 0, + "import/extensions": 0, + "import/no-extraneous-dependencies": 0, + "camelcase": 0, + "template-curly-spacing": 0, + "quotes": 0, + "radix": 0, + "eqeqeq": 0, + "no-lonely-if": 0, + "space-unary-ops": 0, + "block-scoped-var": 0, + "no-extra-bind": 0, + "no-multi-spaces": 0, + "class-methods-use-this": 0, + "key-spacing": 0, + "no-multiple-empty-lines": 0, + "space-in-parens": 0, + "no-case-declarations": 0, + "array-bracket-spacing": 0, + "newline-per-chained-call": 0, + "no-else-return": 0, + "max-len": 0, + "comma-spacing": 0, + "no-useless-concat": 0, + "no-unused-expressions": 0, + "no-sequences": 0, + "no-extra-boolean-cast": 0, + "dot-notation": 0, + "no-param-reassign": 0, + "no-shadow": 0, + "one-var": 0, + "no-alert": 0, + "one-var-declaration-per-line": 0, + "no-script-url": 0, + "wrap-iife": 0, + "no-var": 0, + "vars-on-top": 0, + "space-infix-ops": 0, + "no-irregular-whitespace": 0, + "padded-blocks": 0, + "no-underscore-dangle": 0, + "object-curly-spacing": 0, + "no-undef": 0 + } +} diff --git a/.eslintrc.tests.json b/.eslintrc.tests.json new file mode 100644 index 0000000000..e10e726b80 --- /dev/null +++ b/.eslintrc.tests.json @@ -0,0 +1,47 @@ +{ + "extends": "airbnb-base/legacy", + "env": { + "amd": true, + "mocha": true + }, + "parserOptions": { + "ecmaVersion": 6 + }, + "rules": { + "import/no-amd": 0, + + + + "no-undef": 0, + "one-var": 0, + "indent": 0, + "linebreak-style": 0, + "no-whitespace-before-property": 0, + "object-property-newline": 0, + "global-require": 0, + "semi": 0, + "keyword-spacing": 0, + "no-bitwise": 0, + "no-multi-assign": 0, + "newline-per-chained-call": 0, + "no-spaced-func": 0, + "func-call-spacing": 0, + "max-len": 0, + "space-unary-ops": 0, + "quotes": 0, + "no-unused-vars": 0, + "no-unused-expressions": 0, + "no-underscore-dangle": 0, + "quote-props": 0, + "no-shadow": 0, + "padded-blocks": 0, + "comma-dangle": 0, + "vars-on-top": 0, + "space-before-blocks": 0, + "object-curly-spacing": 0, + "no-param-reassign": 0, + "one-var-declaration-per-line": 0, + "func-names": 0, + "space-before-function-paren": 0 + } +} diff --git a/README.md b/README.md index a578661e68..92599d1deb 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,11 @@ $ ./do test:debug $ ./do qa ``` +- Javascript linter: +```sh +$ ./do lint:javascript +``` + # CSS - [Stylus](https://learnboost.github.io/stylus/) - [Nib extension](http://tj.github.io/nib/) diff --git a/RoboFile.php b/RoboFile.php index 76bef1f032..00f1c8eaea 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -78,6 +78,10 @@ class RoboFile extends \Robo\Tasks { return $this->_exec('./node_modules/webpack/bin/webpack.js --bail'); } + function lintJavascript() { + return $this->_exec('npm run lint'); + } + function compileCss() { $css_files = array( 'assets/css/src/admin.styl', diff --git a/package.json b/package.json index abb54a093a..df1acfd4f0 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,11 @@ { "private": true, + "scripts": { + "lint": "npm run lint6 && npm run lint5 && npm run lint-tests", + "lint6": "eslint -c .eslintrc.es6.json 'assets/js/src/**/*.jsx'", + "lint5": "eslint -c .eslintrc.es5.json 'assets/js/src/**/*.js'", + "lint-tests": "eslint -c .eslintrc.tests.json 'tests/javascript'" + }, "dependencies": { "WP-JS-Hooks": "github:carldanley/WP-JS-Hooks", "backbone": "1.3.3", @@ -29,15 +35,20 @@ "velocity-animate": "1.2.3" }, "devDependencies": { - "expose-loader": "~0.7.3", - "exports-loader": "~0.6.4", - "imports-loader": "~0.7.1", + "amd-inject-loader": "~0.5.0", "babel-core": "^5.8.22", "babel-loader": "^5.3.2", - "amd-inject-loader": "~0.5.0", "chai": "2.2.0", "chai-jq": "0.0.8", + "eslint": "^3.19.0", + "eslint-config-airbnb": "^15.0.1", + "eslint-plugin-import": "^2.3.0", + "eslint-plugin-jsx-a11y": "^5.0.3", + "eslint-plugin-react": "^7.1.0", + "exports-loader": "~0.6.4", + "expose-loader": "~0.7.3", "grunt-cli": "~1.2.0", + "imports-loader": "~0.7.1", "jquery": "2.1.4", "jsdom": "3.1.2", "mocha": "2.2.1",