Skip to content

Commit

Permalink
Run eslint on the scripts directory
Browse files Browse the repository at this point in the history
I noticed that the `scripts` directory, which begins to have a lot of
files as we automate more tasks (like #1524), wasn't linted.

That directory contains code in two languages BASH and JS (Node.js),
with a move to prefer JS files (as it's a JS/TS project).

So I chose to add an `.eslintrc.js` file (which is a deprecated format
but I couldn't make the new one work) and lint script on that directory.

I subsequently fixed some linting errors.

For now, that script isn't run by our GitHub actions, I will see whether
we can do an intelligent kind of runner which detects if scripts have
been updated.
  • Loading branch information
peaBerberian committed Sep 4, 2024
1 parent e5894f8 commit 046bd3f
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 9 deletions.
2 changes: 0 additions & 2 deletions demo/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ module.exports = {
env: {
es6: true,
browser: true,
commonjs: true,
mocha: true,
},

globals: {
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@
"bundle:watch": "./scripts/run_bundler.mjs src/index.ts --production-mode -o dist/rx-player.js --watch",
"certificate": "./scripts/generate_certificate",
"check": "npm run check:types && npm run lint && npm run check:types:unit_tests",
"check:all": "npm run check:types && npm run lint && npm run lint:demo && npm run lint:tests && npm run test:unit && npm run test:integration && npm run test:memory && node -r esm ./scripts/check_nodejs_import_compatibility.js",
"check:all": "npm run check:types && npm run lint && npm run lint:demo && npm run lint:tests && npm run lint:scripts && npm run test:unit && npm run test:integration && npm run test:memory && node -r esm ./scripts/check_nodejs_import_compatibility.js",
"check:demo": "npm run check:demo:types && npm run lint:demo",
"check:demo:types": "tsc --noEmit --project demo/",
"clean:build": "scripts/remove_dir.mjs dist",
"clean:build": "scripts/utils/remove_dir.mjs dist",
"check:types": "tsc --noEmit --project .",
"check:types:unit_tests": "tsc --noEmit --project ./tsconfig.unit-tests.json",
"check:types:watch": "tsc --noEmit --watch --project .",
"clean:wasm": "scripts/remove_dir.mjs dist/mpd-parser.wasm && scripts/remove_dir.mjs ./src/parsers/manifest/dash/wasm-parser/target",
"clean:wasm": "scripts/utils/remove_dir.mjs dist/mpd-parser.wasm && scripts/utis/remove_dir.mjs ./src/parsers/manifest/dash/wasm-parser/target",
"demo": "node ./scripts/build_demo.mjs --production-mode",
"demo:min": "node ./scripts/build_demo.mjs --production-mode --minify",
"demo:watch": "node ./scripts/build_demo.mjs --watch --production-mode",
Expand All @@ -169,6 +169,7 @@
"fmt:rust:check": "cd ./src/parsers/manifest/dash/wasm-parser && cargo fmt --check",
"lint": "eslint src -c .eslintrc.js",
"lint:demo": "eslint -c demo/.eslintrc.js demo/scripts",
"lint:scripts": "eslint -c scripts/.eslintrc.js --ext .js --ext .mjs --ext .cjs scripts",
"lint:tests": "eslint tests/**/*.js --ignore-pattern '/tests/performance/bundle*'",
"list": "node scripts/list-npm-scripts.mjs",
"prepublishOnly": "npm run build:all",
Expand Down
53 changes: 53 additions & 0 deletions scripts/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
module.exports = {
root: true,
parserOptions: {
ecmaVersion: 2020,
sourceType: "module",
},
env: {
es6: true,
node: true,
commonjs: true,
},
extends: ["prettier"],
rules: {
"comma-dangle": [1, "only-multiline"],
"no-cond-assign": 0,
"no-constant-condition": 0,
"no-control-regex": 0,
"no-debugger": 2,
"no-dupe-args": 2,
"no-dupe-keys": 2,
"no-duplicate-case": 1,
"no-empty-character-class": 1,
"no-empty": 0,
"no-ex-assign": 1,
"no-extra-boolean-cast": 1,
"no-extra-parens": [1, "functions"],
"no-extra-semi": 2,
"no-func-assign": 2,
"no-inner-declarations": 0,
"no-invalid-regexp": 1,
"no-irregular-whitespace": 1,
"no-negated-in-lhs": 2,
"no-obj-calls": 2,
"no-regex-spaces": 1,
"no-sparse-arrays": 2,
"no-unreachable": 2,
"use-isnan": 2,
"valid-jsdoc": 0,
"valid-typeof": 2,
"no-unexpected-multiline": 0,
"no-trailing-spaces": 2,
"no-multiple-empty-lines": 1,
"accessor-pairs": [1, { setWithoutGet: true }],
"block-scoped-var": 1,
complexity: 0,
curly: [1, "all"],
"no-case-declarations": 0,
"no-var": 1,
"prefer-const": 1,
"linebreak-style": [1, "unix"],
semi: [1, "always"],
},
};
2 changes: 1 addition & 1 deletion scripts/generate_build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import * as path from "path";
import { fileURLToPath, pathToFileURL } from "url";
import generateEmbeds from "./generate_embeds.mjs";
import runBundler from "./run_bundler.mjs";
import removeDir from "./remove_dir.mjs";
import removeDir from "./utils/remove_dir.mjs";

const currentDirectory = path.dirname(fileURLToPath(import.meta.url));

Expand Down
6 changes: 4 additions & 2 deletions scripts/run_bundler.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,18 @@ if (import.meta.url === pathToFileURL(process.argv[1]).href) {
}

try {
await runBundler(normalizedPath, {
runBundler(normalizedPath, {
watch: shouldWatch,
minify: shouldMinify,
production,
silent,
outfile,
}).catch((err) => {
console.error(`ERROR: ${err}\n`);
process.exit(1);
});
} catch (err) {
console.error(`ERROR: ${err}\n`);
displayHelp();
process.exit(1);
}
}
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/performance/run.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as path from "path";
import { fileURLToPath } from "url";
import launchStaticServer from "../../scripts/launch_static_server.mjs";
import getHumanReadableHours from "../../scripts/utils/get_human_readable_hours.mjs";
import removeDir from "../../scripts/remove_dir.mjs";
import removeDir from "../../scripts/utils/remove_dir.mjs";
import { createContentServer } from "../contents/server.mjs";

const currentDirectory = path.dirname(fileURLToPath(import.meta.url));
Expand Down

0 comments on commit 046bd3f

Please sign in to comment.