From 91913e1f98611a9a648d57cd216cd42799f860b8 Mon Sep 17 00:00:00 2001 From: Mark Vayngrib Date: Fri, 15 Sep 2017 09:57:36 -0400 Subject: [PATCH] add precommit lint --- .eslintrc.js | 283 +++++++++++++++++++++++++++++++++++++++++++++++++++ cmd.js | 2 +- package.json | 7 ++ pkg-hacks.js | 19 ++-- 4 files changed, 300 insertions(+), 11 deletions(-) create mode 100644 .eslintrc.js diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..c9098bc --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,283 @@ +module.exports = { + "env": { + "es6": true, + "node": true + }, + "globals": { + // react native + "window": true, + "__DEV__": true, + "localStorage": true + }, + "extends": "eslint:recommended", + "parserOptions": { + "sourceType": "module" + }, + "rules": { + "accessor-pairs": "error", + "array-bracket-spacing": "warn", + "array-callback-return": "warn", + "arrow-body-style": "warn", + "arrow-parens": [ + "error", + "as-needed" + ], + "arrow-spacing": [ + "error", + { + "after": true, + "before": true + } + ], + "block-scoped-var": "error", + "block-spacing": "error", + "brace-style": [ + "error", + "1tbs" + ], + "callback-return": "error", + "camelcase": "warn", + "capitalized-comments": "off", + "class-methods-use-this": "error", + "comma-dangle": "off", + "comma-spacing": [ + "error", + { + "after": true, + "before": false + } + ], + "comma-style": [ + "error", + "last" + ], + "complexity": "error", + "computed-property-spacing": "error", + "consistent-return": "warn", + "consistent-this": "warn", + "curly": "off", + "default-case": "error", + "dot-location": "off", + "dot-notation": "warn", + "eol-last": "warn", + "eqeqeq": "warn", + "func-call-spacing": "error", + "func-name-matching": "error", + "func-names": "warn", + "func-style": "warn", + "generator-star-spacing": "off", + "global-require": "off", + "guard-for-in": "warn", + "handle-callback-err": "warn", + "id-blacklist": "error", + "id-length": "off", + "id-match": "error", + "indent": "off", + "init-declarations": "off", + "jsx-quotes": "error", + "key-spacing": "error", + "keyword-spacing": [ + "error", + { + "after": true, + "before": true + } + ], + "line-comment-position": "warn", + "linebreak-style": [ + "error", + "unix" + ], + "lines-around-comment": "warn", + "lines-around-directive": "error", + "max-depth": "error", + "max-len": "off", + "max-lines": "warn", + "max-nested-callbacks": "error", + "max-params": "warn", + "max-statements": "off", + "max-statements-per-line": "error", + "multiline-ternary": "warn", + "new-cap": "error", + "new-parens": "error", + "newline-after-var": "off", + "newline-before-return": "off", + "newline-per-chained-call": "warn", + "no-alert": "error", + "no-array-constructor": "error", + "no-await-in-loop": "error", + "no-bitwise": "error", + "no-caller": "error", + "no-case-declarations": "warn", + "no-catch-shadow": "warn", + "no-cond-assign": "warn", + "no-confusing-arrow": "error", + "no-console": "warn", + "no-constant-condition": "warn", + "no-continue": "warn", + "no-div-regex": "error", + "no-duplicate-imports": "error", + "no-else-return": "error", + "no-ex-assign": "off", + "no-empty": [ + "error", + { + "allowEmptyCatch": true + } + ], + "no-empty-function": "off", + "no-eq-null": "warn", + "no-eval": "error", + "no-extend-native": "error", + "no-extra-bind": "error", + "no-extra-label": "error", + "no-extra-parens": "warn", + "no-extra-semi": "warn", + "no-floating-decimal": "error", + "no-implicit-coercion": "warn", + "no-implicit-globals": "error", + "no-implied-eval": "error", + "no-inline-comments": "off", + "no-inner-declarations": "warn", + "no-invalid-this": "warn", + "no-iterator": "error", + "no-label-var": "error", + "no-labels": "error", + "no-lone-blocks": "error", + "no-lonely-if": "warn", + "no-loop-func": "error", + "no-magic-numbers": "off", + "no-mixed-operators": "error", + "no-mixed-requires": "error", + "no-multi-assign": "warn", + "no-multi-spaces": "error", + "no-multi-str": "error", + "no-multiple-empty-lines": "error", + "no-native-reassign": "error", + "no-negated-condition": "warn", + "no-negated-in-lhs": "error", + "no-nested-ternary": "error", + "no-new": "error", + "no-new-func": "error", + "no-new-object": "error", + "no-new-require": "error", + "no-new-wrappers": "error", + "no-octal-escape": "error", + "no-param-reassign": "warn", + "no-path-concat": "error", + "no-process-env": "off", + "no-process-exit": "off", + "no-proto": "error", + "no-prototype-builtins": "error", + "no-restricted-globals": "error", + "no-restricted-imports": "error", + "no-restricted-modules": "error", + "no-restricted-properties": "error", + "no-restricted-syntax": "error", + "no-return-assign": "warn", + "no-return-await": "error", + "no-script-url": "error", + "no-self-compare": "error", + "no-sequences": "error", + "no-shadow": "warn", + "no-shadow-restricted-names": "error", + "no-spaced-func": "error", + "no-sync": "off", + "no-tabs": "error", + "no-template-curly-in-string": "error", + "no-ternary": "off", + "no-throw-literal": "error", + "no-trailing-spaces": "error", + "no-undef-init": "warn", + "no-undefined": "warn", + "no-underscore-dangle": "warn", + "no-unmodified-loop-condition": "error", + "no-unneeded-ternary": "error", + "no-unused-expressions": "error", + "no-unused-vars": "warn", + "no-use-before-define": "off", + "no-useless-call": "error", + "no-useless-computed-key": "error", + "no-useless-concat": "error", + "no-useless-constructor": "error", + "no-useless-escape": "warn", + "no-useless-rename": "error", + "no-useless-return": "error", + "no-var": "warn", + "no-void": "error", + "no-warning-comments": "warn", + "no-whitespace-before-property": "error", + "no-with": "error", + "object-curly-newline": "off", + "object-curly-spacing": [ + "error", + "always" + ], + "object-property-newline": [ + "error", + { + "allowMultiplePropertiesPerLine": true + } + ], + "object-shorthand": "warn", + "one-var": "off", + "one-var-declaration-per-line": "error", + "operator-assignment": "error", + "operator-linebreak": "error", + "padded-blocks": "off", + "prefer-const": "warn", + "prefer-destructuring": "warn", + "prefer-numeric-literals": "error", + "prefer-promise-reject-errors": "error", + "prefer-reflect": "warn", + "prefer-rest-params": "warn", + "prefer-spread": "warn", + "prefer-template": "off", + "quote-props": "off", + "quotes": "off", + "radix": "error", + "require-await": "error", + "require-jsdoc": "off", + "require-yield": "off", + "rest-spread-spacing": [ + "error", + "never" + ], + "semi": "off", + "semi-spacing": "error", + "sort-imports": "error", + "sort-keys": "off", + "sort-vars": "error", + "space-before-blocks": "error", + "space-before-function-paren": "error", + "space-in-parens": [ + "error", + "never" + ], + "space-infix-ops": "off", + "space-unary-ops": "error", + "spaced-comment": [ + "error", + "always" + ], + "strict": "error", + "symbol-description": "error", + "template-curly-spacing": [ + "error", + "never" + ], + "unicode-bom": [ + "error", + "never" + ], + "valid-jsdoc": "warn", + "vars-on-top": "off", + "wrap-iife": "error", + "wrap-regex": "warn", + "yield-star-spacing": "error", + "yoda": [ + "error", + "never" + ] + } +}; diff --git a/cmd.js b/cmd.js index aa35dac..80f1f9f 100755 --- a/cmd.js +++ b/cmd.js @@ -116,7 +116,7 @@ function installShims ({ modules, overwrite }, done) { parallel(shimPkgNames.map(function (name) { var modPath = path.resolve('./node_modules/' + name) - return function (cb) { + return function (cb) { fs.exists(modPath, function (exists) { if (!exists) return cb() diff --git a/package.json b/package.json index dac4bed..484e810 100644 --- a/package.json +++ b/package.json @@ -17,5 +17,12 @@ "run-parallel": "^1.1.2", "semver": "^5.0.1", "xtend": "^4.0.0" + }, + "scripts": { + "lint": "eslint --quiet --ignore-path .gitignore .", + "precommit": "npm run lint" + }, + "devDependencies": { + "husky": "^0.14.3" } } diff --git a/pkg-hacks.js b/pkg-hacks.js index 1c444e5..bbbdd3c 100644 --- a/pkg-hacks.js +++ b/pkg-hacks.js @@ -26,11 +26,11 @@ var path = require('path') module.exports = function hackFiles (hacks) { var finder = find('./node_modules') - hacks = hacks || hackers.map(function (h) { return h.name }) + hacks = hacks || hackers.map(h => h.name) finder.on('file', function (file) { - if (!/\.(js|json)$/.test(file) - || /\/tests?\//.test(file)) { + if (!/\.(js|json)$/.test(file) || + /\/tests?\//.test(file)) { return } @@ -163,7 +163,7 @@ var hackers = [ regex: [ /webtorrent\/lib\/fs-storage\.js/ ], - hack: function(file, contents) { + hack: function (file, contents) { if (isInReactNative(file)) return var fixed = contents.replace(/fs\.existsSync\([^\)]*\)/g, 'false') @@ -177,7 +177,7 @@ var hackers = [ ], hack: function (file, contents) { var fixed = contents.replace(/typeof\ FileReaderSync \!\=\= \'undefined\'/, 'false') - return contents === fixed ? null : fixed + return contents === fixed ? null : fixed } }, { @@ -224,7 +224,7 @@ var hackers = [ regex: [ /levelup\/lib\/util\.js$/ ], - hack: function(file, contents) { + hack: function (file, contents) { if (isInReactNative(file)) return var fixed = contents @@ -257,7 +257,7 @@ var hackers = [ regex: [ /level-jobs\/package\.json$/ ], - hack: function(file, contents) { + hack: function (file, contents) { if (isInReactNative(file)) return var pkg @@ -425,7 +425,7 @@ var hackers = [ regex: [ /bytewise\/bytewise\.js$/ ], - hack: function(file, contents) { + hack: function (file, contents) { if (isInReactNative(file)) return var fixed = contents @@ -532,8 +532,7 @@ function rewireMain (pkg) { var main = pkg.browser || './index.js' pkg.browser = {} pkg.browser[pkg.main] = main - } - else if (typeof pkg.browser === 'undefined') { + } else if (typeof pkg.browser === 'undefined') { pkg.browser = {} } }