Selaa lähdekoodia

refactor: disallow shadowed variables

tophf 2 vuotta sitten
vanhempi
sitoutus
9a7dca8162

+ 1 - 0
.eslintrc.js

@@ -10,6 +10,7 @@ module.exports = {
   plugins: ['jest'],
   rules: {
     'prettier/prettier': 'off',
+    'no-shadow': 2,
     'no-unused-expressions': 2,
     'no-use-before-define': ['error', {
       'functions': false,

+ 1 - 0
src/background/utils/db.js

@@ -307,6 +307,7 @@ export function getScriptsByURL(url, isTop, errors) {
     ]) {
       const listName = STORAGE_ROUTES[name];
       const envCheck = name === S_CACHE ? envStart : env; // envStart cache is reused in injected
+      // eslint-disable-next-line no-shadow
       for (let url of list) {
         url = pathMap[url] || url;
         if (url) {

+ 1 - 1
src/background/utils/options.js

@@ -41,7 +41,7 @@ const callHooksLater = debounce(callHooks, DELAY);
 const writeOptionsLater = debounce(writeOptions, DELAY);
 const optProxy = new Proxy(defaults, { get: (_, key) => getOption(key) });
 export const hookOptions = hooks.hook;
-hookOptions(changes => sendCmd('UpdateOptions', changes));
+hookOptions(data => sendCmd('UpdateOptions', data));
 
 export function initOptions(data) {
   data = data[STORAGE_KEY] || {};

+ 3 - 3
src/background/utils/preinject.js

@@ -245,7 +245,7 @@ function removeStaleCacheEntry(val, key) {
     const prop = propsToClear[prefix];
     if (val[prop]?.includes(+id || id)) {
       if (prefix === S_REQUIRE_PRE) {
-        val.depsMap[id].forEach(id => cache.del(S_SCRIPT_PRE + id));
+        val.depsMap[id].forEach(scriptId => cache.del(S_SCRIPT_PRE + scriptId));
       } else if (prefix === S_VALUE_PRE) {
         val[S_VALUE][id] = newData;
       } else {
@@ -429,7 +429,7 @@ function prepareScript(script, env) {
   const code = env[S_CODE][id];
   const dataKey = getUniqId();
   const winKey = getUniqId();
-  const key = { data: dataKey, win: winKey };
+  const plantKey = { data: dataKey, win: winKey };
   const displayName = getScriptName(script);
   const pathMap = custom.pathMap || {};
   const wrap = !meta[UNWRAP];
@@ -489,7 +489,7 @@ function prepareScript(script, env) {
       uuid: props.uuid,
     },
     id,
-    key,
+    key: plantKey,
     meta: metaCopy,
     pathMap,
     [__CODE]: injectedCode,

+ 2 - 2
src/common/ui/code-js-mixed-mode.js

@@ -94,7 +94,7 @@ CodeMirror.defineMode('javascript-mixed', (config) => {
      * The use case and the solution are both analogous to forceJsModeToQuasi(),
      * which handles tokenizing a single-line string template.
      */
-    function forceHtmlModeToAttrContinuedState(stream, htmlState) {
+    function _forceHtmlModeToAttrContinuedState(stream, htmlState) {
       /*
        * Detect quote type by checking current token last char (use last char instead of
        * first char, because last char also works for multi-lined char value
@@ -117,7 +117,7 @@ CodeMirror.defineMode('javascript-mixed', (config) => {
       }
     }
     return [
-      forceHtmlModeToAttrContinuedState,
+      _forceHtmlModeToAttrContinuedState,
       stateForAttrValue,
     ];
   })();

+ 2 - 4
src/common/ui/message.vue

@@ -53,10 +53,8 @@ export default {
       }
     };
     const onBackdropClick = () => {
-      const { onBackdropClick } = props.message;
-      if (onBackdropClick) {
-        if (onBackdropClick() !== false) dismiss();
-      }
+      const cb = props.message.onBackdropClick;
+      if (cb && cb() !== false) dismiss();
     };
     const content = computed(() => {
       const { text } = props.message;

+ 1 - 1
src/injected/web/requests.js

@@ -174,7 +174,7 @@ export function onRequestCreate(opts, context, fileName) {
       try { url = url::URLToString(); } // safe window.URL getter
       catch (e) {
         try { url = `${url}`; } // unsafe toString may throw e.g. for Symbol or if spoofed
-        catch (e) { err = e; }
+        catch (e2) { err = e2; }
       }
     }
     opts.url = url;

+ 1 - 1
src/options/index.js

@@ -124,7 +124,7 @@ function initMain() {
           store.needRefresh = true;
         } else {
           // Restored from the recycle bin.
-          store.removedScripts = store.removedScripts.filter(script => script.props.id !== where.id);
+          store.removedScripts = store.removedScripts.filter(rs => rs.props.id !== where.id);
         }
       }
       // Update the new list

+ 3 - 4
src/options/views/app.vue

@@ -39,10 +39,6 @@ const tabs = [
 const extName = i18n('extName');
 const conditionNotEdit = '!editScript';
 
-// Speedup and deflicker for initial page load:
-// skip rendering the aside when starting in the editor for a new script.
-const [name, tabFunc] = store.route.paths;
-
 const current = computed(() => {
   const name = store.route.paths[0];
   return tabs.find(tab => tab.name === name) || tabs[0];
@@ -76,6 +72,9 @@ addEventListener('dragover', evt => {
 
 export default {
   setup() {
+    // Speedup and deflicker for initial page load:
+    // skip rendering the aside when starting in the editor for a new script.
+    const [name, tabFunc] = store.route.paths;
     const canRenderAside = ref(name !== SCRIPTS || (tabFunc !== '_new' && !Number(tabFunc)));
 
     watchEffect(() => {

+ 1 - 1
src/options/views/tab-installed.vue

@@ -659,7 +659,7 @@ export default {
     resetList();
     watch(showRecycle, resetList);
     watch(() => store.canRenderScripts && refList.value && draggableRaw.value,
-      state => toggleDragging(refList.value, moveScript, state));
+      dr => toggleDragging(refList.value, moveScript, dr));
     watch(() => state.search, scheduleSearch);
     watch(() => [filters.sort, filters.showEnabledFirst], debouncedUpdate);
     watch(() => filters.viewSingleColumn, adjustScriptWidth);