Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint only changed files #1115

Merged
merged 9 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Use Node.js 16.x
uses: actions/setup-node@v1
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
"build:jsdocs": "node ./build/scripts/docs/index.js",
"test": "node ./build/scripts/test.js",
"coverage": "node ./build/scripts/test.js --coverage",
"lint": "eslint . --cache",
"lint:fix": "eslint . --fix --cache",
"lint": "node ./build/scripts/lint.js --cache",
"lint:all": "node ./build/scripts/lint.js --cache --all",
"lint:fix": "node ./build/scripts/lint.js --cache --fix",
"lint:fix:all": "node ./build/scripts/lint.js --cache --fix --all",
"postinstall": "tsc --project ./scripts/tsconfig.json && copyfiles ./scripts/utils/browser/openChrome.applescript ./build"
},
"devDependencies": {
Expand Down Expand Up @@ -77,6 +79,7 @@
"react-refresh-typescript": "^2.0.7",
"sass": "^1.53.0",
"sass-loader": "^13.0.2",
"simple-git": "^3.14.1",
"ts-jest": "^28.0.5",
"ts-loader": "^9.3.1",
"ts-morph": "^15.1.0",
Expand Down
44 changes: 44 additions & 0 deletions scripts/lint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {ESLint} from "eslint";
import {simpleGit} from "simple-git";
import yargs from "yargs";


// CLI
(async () => {
const { fix, cache, all } = await yargs(process.argv.slice(2))
.boolean("fix")
.boolean("cache")
.boolean("all")
.argv;

const eslint = new ESLint({
fix, cache,
errorOnUnmatchedPattern: false, // disable because deleted files
extensions: [".ts", ".tsx"],
});

const files: string[] = [];
if (!all) {
const git = simpleGit();
const diff = await git.diff(["--name-only", "origin/master...", "--"]);
diff.split("\n").filter((file) => (file.endsWith(".ts") || file.endsWith(".tsx"))).forEach((file) => {
LeonMontealegre marked this conversation as resolved.
Show resolved Hide resolved
if (file.endsWith(".ts") || file.endsWith(".tsx"))
LeonMontealegre marked this conversation as resolved.
Show resolved Hide resolved
files.push(file);
});
const status = await git.status(["--short"]);
LeonMontealegre marked this conversation as resolved.
Show resolved Hide resolved
status.files.forEach((summary) => {
const file = summary.path;
if (file.endsWith(".ts") || file.endsWith(".tsx"))
files.push(file);
});
} else {
files.push("scripts/", "src/");
}

const results = await eslint.lintFiles(files);
if (fix)
await ESLint.outputFixes(results);
const formatter = await eslint.loadFormatter("stylish");
const resultText = formatter.format(results);
console.log(resultText);
})();
21 changes: 21 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2061,6 +2061,18 @@
"@jridgewell/resolve-uri" "^3.0.3"
"@jridgewell/sourcemap-codec" "^1.4.10"

"@kwsites/file-exists@^1.1.1":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@kwsites/file-exists/-/file-exists-1.1.1.tgz#ad1efcac13e1987d8dbaf235ef3be5b0d96faa99"
integrity sha512-m9/5YGR18lIwxSFDwfE3oA7bWuq9kdau6ugN4H2rJeyhFQZcG9AgSHkQtSD15a8WvTgfz9aikZMrKPHvbpqFiw==
dependencies:
debug "^4.1.1"

"@kwsites/promise-deferred@^1.1.1":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@kwsites/promise-deferred/-/promise-deferred-1.1.1.tgz#8ace5259254426ccef57f3175bc64ed7095ed919"
integrity sha512-GaHYm+c0O9MjZRu0ongGBRbinu8gVAMd2UZjji6jVmqKtZluZnptXGWhz1E8j8D2HJ3f/yMxKAUC0b+57wncIw==

"@leichtgewicht/ip-codec@^2.0.1":
version "2.0.4"
resolved "https://registry.yarnpkg.com/@leichtgewicht/ip-codec/-/ip-codec-2.0.4.tgz#b2ac626d6cb9c8718ab459166d4bb405b8ffa78b"
Expand Down Expand Up @@ -10304,6 +10316,15 @@ signal-exit@^3.0.2, signal-exit@^3.0.3, signal-exit@^3.0.7:
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.7.tgz#a9a1767f8af84155114eaabd73f99273c8f59ad9"
integrity sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==

simple-git@^3.14.1:
version "3.14.1"
resolved "https://registry.yarnpkg.com/simple-git/-/simple-git-3.14.1.tgz#68018a5f168f8a568862e30b692004b37c3b5ced"
integrity sha512-1ThF4PamK9wBORVGMK9HK5si4zoGS2GpRO7tkAFObA4FZv6dKaCVHLQT+8zlgiBm6K2h+wEU9yOaFCu/SR3OyA==
dependencies:
"@kwsites/file-exists" "^1.1.1"
"@kwsites/promise-deferred" "^1.1.1"
debug "^4.3.4"

sirv@^1.0.7:
version "1.0.19"
resolved "https://registry.yarnpkg.com/sirv/-/sirv-1.0.19.tgz#1d73979b38c7fe91fcba49c85280daa9c2363b49"
Expand Down