Skip to content

Commit

Permalink
Merge pull request #25 from paleite/update-tooling
Browse files Browse the repository at this point in the history
Update tooling
  • Loading branch information
paleite authored Jul 29, 2022
2 parents 48b2831 + e6f2102 commit 9a4d098
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const typescriptProjects = ["./tsconfig.json", "./tsconfig.eslint.json"];
/** @type import("eslint").Linter.Config */
module.exports = {
root: true,
extends: ["@paleite"],
extends: ["@paleite", "plugin:diff/diff"],
parserOptions: { project: typescriptProjects, tsconfigRootDir: __dirname },
overrides: [
{
Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/eslint-plugin-diff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ jobs:
- uses: actions/checkout@v3
- name: Install modules
run: yarn
- name: Link the plugin
run: |
yarn link
yarn link "eslint-plugin-diff"
- name: Fetch the base branch
run: git fetch origin ${{ github.event.pull_request.base.ref }}:${{ github.event.pull_request.base.ref }}
- name: Run ESLint on your changes only
env:
ESLINT_PLUGIN_DIFF_COMMIT: $GITHUB_HEAD_REF
run: eslint --ext .js,.jsx,.ts,.tsx .
ESLINT_PLUGIN_DIFF_COMMIT: ${{ github.event.pull_request.base.ref }}
run: npx --no-install eslint --ext .js,.jsx,.ts,.tsx .
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,23 @@ To lint all the changes of a PR, you only have to set

### For GitHub Actions

```sh
export ESLINT_PLUGIN_DIFF_COMMIT="origin/$GITHUB_BASE_REF";
npx --no-install eslint --ext .js,.ts,.tsx .
```yml
name: Run ESLint on your changes only
on:
pull_request:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install modules
run: npm install
- name: Fetch the base branch
run: git fetch origin ${{ github.event.pull_request.base.ref }}:${{ github.event.pull_request.base.ref }}
- name: Run ESLint on your changes only
env:
ESLINT_PLUGIN_DIFF_COMMIT: ${{ github.event.pull_request.base.ref }}
run: npx --no-install eslint --ext .js,.jsx,.ts,.tsx .
```
### For BitBucket Pipelines
Expand Down
14 changes: 1 addition & 13 deletions lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
const { eslintFiles } = require("eslint-files");

module.exports = {
"*.{html,json,md,yaml,yml}": ["prettier --write"],
"*.{js,ts}": [
() => "yarn run typecheck",
"jest --bail --findRelatedTests --passWithNoTests",
/**
* @param {string[]} files
*/
async (files) =>
`eslint --fix --max-warnings=0 ${await eslintFiles(files)}`,
"prettier --write",
],
"*.ts": [() => "yarn run typecheck"],
};
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@
"build": "tsc --build tsconfig.build.json",
"clean": "tsc --build tsconfig.build.json --clean",
"format": "prettier --write .",
"postinstall": "husky install",
"lint": "eslint --cache --ext .js,.ts --fix .",
"minify": "find dist/ -maxdepth 1 -iname '*.js' -exec node_modules/.bin/terser --compress --ecma 2020 --mangle --module --output {} -- {} \\;",
"prepare": "husky install",
"prepublishOnly": "pinst --disable",
"prepublish": "yarn run clean && yarn run build && yarn run minify",
"postpublish": "pinst --enable",
"release": "np",
"size": "size-limit",
"test": "jest --coverage",
"typecheck": "tsc --project tsconfig.json",
"minify": "find dist/ -maxdepth 1 -iname '*.js' -exec node_modules/.bin/terser --compress --ecma 2020 --mangle --module --output {} -- {} \\;"
"typecheck": "tsc --project tsconfig.json --noEmit"
},
"devDependencies": {
"@paleite/eslint-config": "^1.0.2",
Expand All @@ -56,7 +56,6 @@
"@typescript-eslint/parser": "^5.27.0",
"eslint": "^8.17.0",
"eslint-config-prettier": "^8.5.0",
"eslint-files": "^1.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-promise": "^6.0.0",
"husky": "^8.0.1",
Expand Down
9 changes: 5 additions & 4 deletions src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const getDiffForFile = (filePath: string, staged = false): string => {
[]
);

return child_process.execFileSync(COMMAND, args).toString();
return child_process.execFileSync(COMMAND, args, options).toString();
};

const getDiffFileList = (staged = false): string[] => {
Expand All @@ -42,7 +42,7 @@ const getDiffFileList = (staged = false): string[] => {
);

return child_process
.execFileSync(COMMAND, args)
.execFileSync(COMMAND, args, options)
.toString()
.trim()
.split("\n")
Expand All @@ -62,14 +62,15 @@ const hasCleanIndex = (filePath: string): boolean => {

let result = true;
try {
child_process.execFileSync(COMMAND, args).toString();
child_process.execFileSync(COMMAND, args, options).toString();
} catch (err: unknown) {
result = false;
}

return result;
};

const options = { maxBuffer: 1024 * 1024 * 100 };
const getUntrackedFileList = (staged = false): string[] => {
if (staged) {
return [];
Expand All @@ -78,7 +79,7 @@ const getUntrackedFileList = (staged = false): string[] => {
const args = ["ls-files", "--exclude-standard", "--others"];

const untrackedFileListCache = child_process
.execFileSync(COMMAND, args)
.execFileSync(COMMAND, args, options)
.toString()
.trim()
.split("\n")
Expand Down
2 changes: 0 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"extends": "./tsconfig.build.json",
"compilerOptions": {
"composite": false,
"noEmit": true,
"rootDir": "."
},

Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1875,11 +1875,6 @@ eslint-config-prettier@^8.5.0:
resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-8.5.0.tgz#5a81680ec934beca02c7b1a61cf8ca34b66feab1"
integrity sha512-obmWKLUNCnhtQRKc+tmnYuQl0pFU1ibYJQ5BGhTVB08bHe9wC8qUeG7c08dj9XX+AuPj1YSGSQIHl1pnDHZR0Q==

eslint-files@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/eslint-files/-/eslint-files-1.0.0.tgz#82a1afcc4b2ab5ae7c6b9b472bd2d1ebc7be2e58"
integrity sha512-nwNfDKR7+R9X/ZXQLVqsaIVTVre/59Yg+M2eOoBS6E/qaz0fWYugrX3XT2j1C288ImRc2SeFvyIm7uyaLq8AHg==

eslint-import-resolver-node@^0.3.6:
version "0.3.6"
resolved "https://registry.yarnpkg.com/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.6.tgz#4048b958395da89668252001dbd9eca6b83bacbd"
Expand Down

0 comments on commit 9a4d098

Please sign in to comment.