From 2fd531e2536b2e58a0f049b7500a896916638719 Mon Sep 17 00:00:00 2001 From: eight Date: Mon, 1 Oct 2018 22:03:17 +0800 Subject: [PATCH] Rewrite linter system (#487) * Add: implement new linter system * Refactor: pull out editor worker * Switch to new linter and worker * Enable eslint cache * Fix: undefined error * Windows compatibility * Fix: refresh linter if the editor.linter changes * Add: stylelint * Add: getStylelintRules, getCsslintRules * Fix: logic to get correct linter * WIP: linter-report * Fix: toggle hidden state * Add: matain the order of lint report for section editor * Add: unhook event * Add: gotoLintIssue * Fix: shouldn't delete rule.init * Add: linter-help-dialog * Drop linterConfig * Add: linter-config-dialog, cacheFn * Add: use cacheFn * Drop lint.js * Add: refresh. Fix report order * Fix: hide empty table * Add: updateCount. Fix table caption * Switch to new linter/worker * Fix: remove unneeded comment * Fix: cacheFn -> cacheFirstCall * Fix: use cacheFirstCall * Fix: cache metaIndex * Fix: i < trs.length * Fix: drop isEmpty * Fix: expose some simple states to global * Fix: return object code style * Fix: use proxy to reflect API * Fix: eslint-disable-line -> eslint-disable-next-line * Fix: requestId -> id * Fix: one-liner * Fix: one-liner * Fix: move dom event block to top * Fix: pending -> pendingResponse * Fix: onSuccess -> onUpdated * Fix: optimize row removing when i === 0 * Fix: hook/unhook -> enableForEditor/disableForEditor * Fix: linter.refresh -> linter.run * Fix: some shadowing * Fix: simplify getAnnotations * Fix: cacheFirstCall -> memoize * Fix: table.update -> table.updateCaption * Fix: unneeded reassign * Fix: callbacks -> listeners * Fix: don't compose but extend * Refactor: replace linter modules with linter-defaults and linter-engines * Fix: implement linter fallbacks * Fix: linter.onChange -> linter.onLintingUpdated * Fix: cms -> tables * Fix: parseMozFormat is not called correctly * Move csslint-loader to background * Fix: watch config changes * Fix: switch to LINTER_DEFAULTS * Fix: csslint-loader -> parserlib-loader --- .gitignore | 1 + background/parserlib-loader.js | 9 + edit.html | 15 +- edit/codemirror-editing-hooks.js | 5 +- edit/csslint-loader.js | 41 -- edit/edit.css | 3 + edit/edit.js | 31 +- edit/editor-worker-body.js | 118 ++++++ edit/editor-worker.js | 39 ++ edit/lint-codemirror-helper.js | 43 --- edit/lint-defaults-csslint.js | 50 --- edit/lint-defaults-stylelint.js | 170 -------- edit/lint.js | 558 --------------------------- edit/linter-config-dialog.js | 196 ++++++++++ edit/linter-defaults.js | 219 +++++++++++ edit/linter-engines.js | 113 ++++++ edit/linter-help-dialog.js | 51 +++ edit/linter-meta.js | 47 +++ edit/linter-report.js | 165 ++++++++ edit/linter.js | 65 ++++ edit/sections.js | 15 +- edit/source-editor.js | 27 +- edit/stylelint-loader.js | 58 --- edit/util.js | 13 + js/usercss.js | 2 +- package.json | 2 +- vendor-overwrites/csslint/csslint.js | 2 +- 27 files changed, 1090 insertions(+), 968 deletions(-) create mode 100644 background/parserlib-loader.js delete mode 100644 edit/csslint-loader.js create mode 100644 edit/editor-worker-body.js create mode 100644 edit/editor-worker.js delete mode 100644 edit/lint-codemirror-helper.js delete mode 100644 edit/lint-defaults-csslint.js delete mode 100644 edit/lint-defaults-stylelint.js delete mode 100644 edit/lint.js create mode 100644 edit/linter-config-dialog.js create mode 100644 edit/linter-defaults.js create mode 100644 edit/linter-engines.js create mode 100644 edit/linter-help-dialog.js create mode 100644 edit/linter-meta.js create mode 100644 edit/linter-report.js create mode 100644 edit/linter.js delete mode 100644 edit/stylelint-loader.js diff --git a/.gitignore b/.gitignore index 29432c99..8b786b66 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ node_modules/ package-lock.json yarn.lock *.zip +.eslintcache diff --git a/background/parserlib-loader.js b/background/parserlib-loader.js new file mode 100644 index 00000000..8275e8fd --- /dev/null +++ b/background/parserlib-loader.js @@ -0,0 +1,9 @@ +/* global importScripts parserlib CSSLint parseMozFormat */ +'use strict'; + +importScripts('/vendor-overwrites/csslint/parserlib.js', '/js/moz-parser.js'); +parserlib.css.Tokens[parserlib.css.Tokens.COMMENT].hide = false; + +self.onmessage = ({data}) => { + self.postMessage(parseMozFormat(data)); +}; diff --git a/edit.html b/edit.html index d99c00c9..8463a984 100644 --- a/edit.html +++ b/edit.html @@ -25,7 +25,6 @@ - @@ -65,6 +64,8 @@ + + @@ -87,6 +88,16 @@ + + + + + + + + + +