mozilla / shield-cloudstorage

INACTIVE - http://mzl.la/ghe-archive - Add-on for cloud storage shield experiment
Mozilla Public License 2.0
2 stars 9 forks source link

Add ESLint and Stylelint for JS and CSS greatness #16

Closed pdehaan closed 6 years ago

pdehaan commented 6 years ago

Rough first stab at implementation...

package.json:

{
  "name": "cloud-storage-shield-study-webextension-experiment",
  "description": "Cloud Storage Shield study as WebExtension Experiments",
  "version": "1.0.0",
  "author": "Mozilla",
  "bugs": {
    "url": "https://github.com/mozilla/shield-cloudstorage/issues"
  },
  "dependencies": {},
  "devDependencies": {
    "eslint": "4.19.1",
    "eslint-plugin-json": "1.2.0",
    "eslint-plugin-mozilla": "0.10.0",
    "eslint-plugin-no-unsanitized": "3.0.0",
    "npm-run-all": "4.1.2",
    "stylelint": "9.2.0",
    "stylelint-config-recommended": "2.1.0",
    "web-ext": "2.6.0"
  },
  "homepage": "https://github.com/mozilla/shield-cloudstorage#readme",
  "keywords": [],
  "license": "MPL-2.0",
  "private": "true",
  "repository": {
    "type": "git",
    "url": "git+https://github.com/mozilla/shield-cloudstorage.git"
  },
  "scripts": {
    "firefox": "web-ext run -s webextension -f nightly",
    "lint": "npm-run-all lint:*",
    "lint:css": "stylelint 'webextension/skin/*.css'",
    "lint:js": "eslint webextension --ext=js,json,jsm",
    "test": "npm run lint"
  }
}

.eslintrc.js:

module.exports = {
  env: {
    browser: true,
    es6: true,
    webextensions: true,
  },
  extends: [
    "eslint:recommended",
    "plugin:mozilla/recommended",
  ],
  plugins: [
    "json",
    "mozilla",
  ],
  root: true,
  rules: {
    "eqeqeq": "error",
    "indent": ["error", 2],
    "no-console": "warn",
    "no-var": "error",
    "no-warning-comments": ["warn", {terms: ["todo", "tbd", "fixme"], location: "anywhere"}],
    "prefer-const": "error",
    "quotes": ["error", "double"],
    "require-await": "error",
    "semi": ["error", "always"],
  }
};

.stylelintrc

{
  "extends": "stylelint-config-recommended"
}
pdehaan commented 6 years ago

I auto-fixed a bunch of the ESLint issues locally using $ npm run lint:js -- --fix, but there are still a few issues you may want to tweak manually (or modify ESLint rules/config):

$ npm run lint:js

> cloud-storage-shield-study-webextension-experiment@1.0.0 lint:js /Users/pdehaan/dev/github/mozilla/shield-cloudstorage
> eslint webextension --ext=js,json,jsm

/Users/pdehaan/dev/github/mozilla/shield-cloudstorage/webextension/background.js
   2:3  error    Move function declaration to program root  no-inner-declarations
   3:2  error    Mixed spaces and tabs                      no-mixed-spaces-and-tabs
   3:4  error    Unexpected tab character                   no-tabs
   3:4  warning  Unexpected console statement               no-console
   4:2  error    Mixed spaces and tabs                      no-mixed-spaces-and-tabs
   4:4  error    Unexpected tab character                   no-tabs
   5:2  error    Unexpected tab character                   no-tabs
   5:2  error    Mixed spaces and tabs                      no-mixed-spaces-and-tabs
   6:2  error    Unexpected tab character                   no-tabs
   6:2  error    Mixed spaces and tabs                      no-mixed-spaces-and-tabs
   6:8  warning  Unexpected console statement               no-console
   7:2  error    Mixed spaces and tabs                      no-mixed-spaces-and-tabs
   7:2  error    Unexpected tab character                   no-tabs
   8:2  error    Unexpected tab character                   no-tabs
   8:2  error    Mixed spaces and tabs                      no-mixed-spaces-and-tabs
  11:3  error    Move function declaration to program root  no-inner-declarations
  12:2  error    Mixed spaces and tabs                      no-mixed-spaces-and-tabs
  12:4  warning  Unexpected console statement               no-console
  12:4  error    Unexpected tab character                   no-tabs
  13:2  error    Mixed spaces and tabs                      no-mixed-spaces-and-tabs
  13:4  error    Unexpected tab character                   no-tabs
  14:2  error    Unexpected tab character                   no-tabs
  14:2  error    Mixed spaces and tabs                      no-mixed-spaces-and-tabs
  15:2  error    Unexpected tab character                   no-tabs
  15:2  error    Mixed spaces and tabs                      no-mixed-spaces-and-tabs
  15:8  warning  Unexpected console statement               no-console
  16:2  error    Unexpected tab character                   no-tabs
  16:2  error    Mixed spaces and tabs                      no-mixed-spaces-and-tabs
  17:2  error    Unexpected tab character                   no-tabs
  17:2  error    Mixed spaces and tabs                      no-mixed-spaces-and-tabs
  23:3  warning  Unexpected console statement               no-console

/Users/pdehaan/dev/github/mozilla/shield-cloudstorage/webextension/privileged/ui/CloudDownloadsView.jsm
   23:7   error  Ci is now defined in global scope, a separate definition is no longer necessary  mozilla/no-define-cc-etc
   23:12  error  Use Ci rather than Components.interfaces                                         mozilla/use-cc-etc
   25:1   error  Unexpected var, use let or const instead                                         no-var
  348:23  error  Expected '===' and instead saw '=='                                              eqeqeq
  473:5   error  Unexpected lexical declaration in case block                                     no-case-declarations
  473:5   error  Unexpected lexical declaration in case block                                     no-case-declarations
  485:1   error  Unexpected var, use let or const instead                                         no-var
  621:1   error  Unexpected var, use let or const instead                                         no-var
  641:73  error  Expected '===' and instead saw '=='                                              eqeqeq
  642:73  error  Expected '===' and instead saw '=='                                              eqeqeq

/Users/pdehaan/dev/github/mozilla/shield-cloudstorage/webextension/privileged/ui/cloudstorage.js
  15:36  error    Cu.import imports into variables and into global scope  mozilla/no-import-into-var-and-global
  22:11  warning  Unexpected console statement                            no-console

✖ 43 problems (37 errors, 6 warnings)

And stylelint reports a few errors, which may be worth investigating:

$ npm run lint:css

> cloud-storage-shield-study-webextension-experiment@1.0.0 lint:css /Users/pdehaan/dev/github/mozilla/shield-cloudstorage
> stylelint 'webextension/skin/*.css'

webextension/skin/clouddownloads.css
  15:1   ✖  Unexpected unknown type selector "richlistitem"                                 selector-type-no-unknown
  19:1   ✖  Unexpected unknown type selector "richlistitem"                                 selector-type-no-unknown
  55:1   ✖  Unexpected duplicate selector "#cloudDownloadTypeIcon", first used at line 48   no-duplicate-selectors
  75:22  ✖  Unexpected unknown type selector "radio"                                        selector-type-no-unknown
  88:22  ✖  Unexpected unknown type selector "radio"                                        selector-type-no-unknown
  92:22  ✖  Unexpected unknown type selector "radio"                                        selector-type-no-unknown
 126:32  ✖  Unexpected unknown type selector "menuseparator"                                selector-type-no-unknown
punamdahiya commented 6 years ago

@pdehaan +1, Thanks for filing, will run lint and update PR with fixes

punamdahiya commented 6 years ago

PR updated with the fix