Bläddra i källkod

chore: enable eslint for build scripts

tophf 4 år sedan
förälder
incheckning
7ed25dfcab
5 ändrade filer med 34 tillägg och 19 borttagningar
  1. 4 0
      .eslintignore
  2. 11 0
      .eslintrc.js
  3. 4 4
      gulpfile.js
  4. 1 1
      scripts/plaid.conf.js
  5. 14 14
      scripts/webpack.conf.js

+ 4 - 0
.eslintignore

@@ -1,4 +1,8 @@
 **/*.js
 !src/**
 !test/**
+!scripts/fake-dep-loader.js
+!scripts/plaid.conf.js
+!scripts/webpack.conf.js
+!gulpfile.js
 src/public/**

+ 11 - 0
.eslintrc.js

@@ -58,6 +58,17 @@ module.exports = {
         message: 'Array destructuring in an unsafe environment',
       }],
     },
+  }, {
+    // build scripts
+    files: [
+      '*.js',
+      'scripts/*.js',
+    ],
+    env: { node: true },
+    rules: {
+      'global-require': 0,
+      'import/newline-after-import': 0,
+    }
   }],
   rules: {
     'import/extensions': ['error', 'ignorePackages', {

+ 4 - 4
gulpfile.js

@@ -55,7 +55,7 @@ async function manifest() {
 }
 
 async function createIcons() {
-  const ALPHA = .5;
+  const ALPHA = 0.5;
   const dist = `${DIST}/public/images`;
   await fs.mkdir(dist, { recursive: true });
   const icon = Sharp(`src/resources/icon${isBeta() ? '-beta' : ''}.png`);
@@ -73,7 +73,7 @@ async function createIcons() {
   ];
   const handle = (size, type = '', image = icon) => {
     let res = image.clone().resize({ width: size });
-    if (size < 48) res = res.sharpen(size < 32 ? .5 : .25);
+    if (size < 48) res = res.sharpen(size < 32 ? 0.5 : 0.25);
     return res.toFile(`${dist}/icon${size}${type}.png`);
   };
   const darkenOuterEdge = async img => img.composite([{
@@ -83,7 +83,7 @@ async function createIcons() {
   const handle16 = async ([type, image]) => {
     const res = image.clone()
     .resize({ width: 18 })
-    .sharpen(.5, 0)
+    .sharpen(0.5, 0)
     .extract({ left: 1, top: 2, width: 16, height: 16 });
     return (type === 'w' ? res : await darkenOuterEdge(res))
     .toFile(`${dist}/icon16${type}.png`);
@@ -158,7 +158,7 @@ function copyZip() {
     'node_modules/@zip.js/zip.js/dist/zip-no-worker.min.js',
     'node_modules/@zip.js/zip.js/dist/z-worker.js',
   ])
-    .pipe(gulp.dest(`${DIST}/public/lib`));
+  .pipe(gulp.dest(`${DIST}/public/lib`));
 }
 
 const pack = gulp.parallel(manifest, createIcons, copyI18n);

+ 1 - 1
scripts/plaid.conf.js

@@ -19,7 +19,7 @@ exports.pages = [
     html: options => ({
       ...options,
       title: 'Violentmonkey',
-      injectTo: item => (item.attributes.src || '').endsWith('/index.js') ? 'body' : 'head',
+      injectTo: item => ((item.attributes.src || '').endsWith('/index.js') ? 'body' : 'head'),
     }),
   },
 }), {});

+ 14 - 14
scripts/webpack.conf.js

@@ -15,7 +15,7 @@ const pickEnvs = (items) => {
   return Object.assign({}, ...items.map(x => ({
     [`process.env.${x.key}`]: JSON.stringify(
       'val' in x ? x.val
-        : process.env[x.key] ?? x.def
+        : process.env[x.key] ?? x.def,
     ),
   })));
 };
@@ -79,7 +79,7 @@ const modify = (page, entry, init) => modifyWebpackConfig(
   }, {
     projectConfig: {
       ...mergedConfig,
-      ...entry && { pages: { [page]: { entry }} },
+      ...entry && { pages: { [page]: { entry } } },
     },
   },
 );
@@ -94,18 +94,20 @@ module.exports = Promise.all([
     /* Embedding as <style> to ensure uiTheme option doesn't cause FOUC.
      * Note that in production build there's no <head> in html but document.head is still
      * auto-created per the specification so our styles will be placed correctly anyway. */
-    if (isProd) config.plugins.push(new HTMLInlineCSSWebpackPlugin({
-      replace: {
-        target: '<body>',
-        position: 'before',
-      },
-    }));
+    if (isProd) {
+      config.plugins.push(new HTMLInlineCSSWebpackPlugin({
+        replace: {
+          target: '<body>',
+          position: 'before',
+        },
+      }));
+    }
     config.plugins.push(new class ListBackgroundScripts {
       apply(compiler) {
         compiler.hooks.afterEmit.tap(this.constructor.name, compilation => {
           const dist = compilation.outputOptions.path;
           const path = `${dist}/manifest.json`;
-          const manifest = JSON.parse(fs.readFileSync(path, {encoding: 'utf8'}));
+          const manifest = JSON.parse(fs.readFileSync(path, { encoding: 'utf8' }));
           const bgId = 'background/index';
           const bgEntry = compilation.entrypoints.get(bgId);
           const scripts = bgEntry.chunks.map(c => c.files[0]);
@@ -113,14 +115,12 @@ module.exports = Promise.all([
             manifest.background.scripts = scripts;
             fs.writeFileSync(path,
               JSON.stringify(manifest, null, isProd ? 0 : 2),
-              {encoding: 'utf8'});
+              { encoding: 'utf8' });
           }
-          try {
-            fs.unlinkSync(`${dist}/${bgId}.html`);
-          } catch (e) {}
+          fs.promises.unlink(`${dist}/${bgId}.html`).catch(() => {});
         });
       }
-    });
+    }());
   }),
   modify('injected', './src/injected', (config) => {
     addWrapper(config, getGlobals => ({