refactor(ci): Lint PR diffs only (#4137)

*  Set up `eslint-plugin-diff`

* 🔧 Fix setup

* ⬆️ Upgrade `checkout` and `setup-node`

* 🔧 Fix YAML

* 🧪 Verify `eslint-plugin-diff` behavior

* Revert "🧪 Verify `eslint-plugin-diff` behavior"

This reverts commit 1fcc6c8299.

* ✏️ Fix comment
This commit is contained in:
Iván Ovejero 2022-09-21 10:24:39 +02:00 committed by GitHub
parent 97cd564f7b
commit a2441b8e3f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 13 deletions

View file

@ -13,18 +13,27 @@ jobs:
node-version: [14.x, 16.x] node-version: [14.x, 16.x]
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }} - name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3 uses: actions/setup-node@v3
with: with:
node-version: ${{ matrix.node-version }} node-version: ${{ matrix.node-version }}
cache: 'npm' cache: 'npm'
- name: npm install, build, and test
run: | - name: Install npm and dependencies
npm install -g npm@latest run: npm install -g npm@latest && npm install
npm install
npm run build --if-present - name: Build
npm test run: npm run build --if-present
npm run lint
- name: Test
run: npm run test
- name: Fetch base branch for `git diff`
run: git fetch origin ${{ github.event.pull_request.base.ref }}:${{ github.event.pull_request.base.ref }}
- name: Run ESLint on changes only
env: env:
CI: true ESLINT_PLUGIN_DIFF_COMMIT: ${{ github.event.pull_request.base.ref }}
run: npm run lint

20
package-lock.json generated
View file

@ -21790,6 +21790,18 @@
"ms": "^2.1.1" "ms": "^2.1.1"
} }
}, },
"node_modules/eslint-plugin-diff": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/eslint-plugin-diff/-/eslint-plugin-diff-2.0.1.tgz",
"integrity": "sha512-qqbvwaaO1cfkUprliqiRojRsD0qGsvzmJNqNrb9s0h15sDVzZMXYdu0TUFpUwauLeU28etSsfWIp0Uu+OAcXXw==",
"dev": true,
"engines": {
"node": ">=14.0.0"
},
"peerDependencies": {
"eslint": ">=6.7.0"
}
},
"node_modules/eslint-plugin-import": { "node_modules/eslint-plugin-import": {
"version": "2.26.0", "version": "2.26.0",
"resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.26.0.tgz", "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.26.0.tgz",
@ -52138,6 +52150,7 @@
"eslint": "8.23.0", "eslint": "8.23.0",
"eslint-config-airbnb-typescript": "^17.0.0", "eslint-config-airbnb-typescript": "^17.0.0",
"eslint-config-prettier": "^8.5.0", "eslint-config-prettier": "^8.5.0",
"eslint-plugin-diff": "^2.0.1",
"eslint-plugin-import": "^2.26.0", "eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4.2.1", "eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-vue": "^9.4.0" "eslint-plugin-vue": "^9.4.0"
@ -55958,6 +55971,7 @@
"eslint": "8.23.0", "eslint": "8.23.0",
"eslint-config-airbnb-typescript": "^17.0.0", "eslint-config-airbnb-typescript": "^17.0.0",
"eslint-config-prettier": "^8.5.0", "eslint-config-prettier": "^8.5.0",
"eslint-plugin-diff": "^2.0.1",
"eslint-plugin-import": "^2.26.0", "eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4.2.1", "eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-vue": "^9.4.0" "eslint-plugin-vue": "^9.4.0"
@ -70014,6 +70028,12 @@
} }
} }
}, },
"eslint-plugin-diff": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/eslint-plugin-diff/-/eslint-plugin-diff-2.0.1.tgz",
"integrity": "sha512-qqbvwaaO1cfkUprliqiRojRsD0qGsvzmJNqNrb9s0h15sDVzZMXYdu0TUFpUwauLeU28etSsfWIp0Uu+OAcXXw==",
"dev": true
},
"eslint-plugin-import": { "eslint-plugin-import": {
"version": "2.26.0", "version": "2.26.0",
"resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.26.0.tgz", "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.26.0.tgz",

View file

@ -33,6 +33,13 @@ module.exports = {
* https://github.com/prettier/eslint-plugin-prettier * https://github.com/prettier/eslint-plugin-prettier
*/ */
'eslint-plugin-prettier', 'eslint-plugin-prettier',
/**
* Plugin to lint only changes
*
* https://github.com/paleite/eslint-plugin-diff#plugindiffdiff-recommended
*/
'eslint-plugin-diff',
], ],
extends: [ extends: [
@ -64,6 +71,13 @@ module.exports = {
* https://github.com/prettier/eslint-config-prettier * https://github.com/prettier/eslint-config-prettier
*/ */
'eslint-config-prettier', 'eslint-config-prettier',
/**
* Config for eslint-plugin-diff
*
* https://github.com/paleite/eslint-plugin-diff#plugindiffdiff-recommended
*/
'plugin:diff/diff',
], ],
rules: { rules: {
@ -180,10 +194,7 @@ module.exports = {
/** /**
* https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/explicit-member-accessibility.md * https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/explicit-member-accessibility.md
*/ */
'@typescript-eslint/explicit-member-accessibility': [ '@typescript-eslint/explicit-member-accessibility': ['error', { accessibility: 'no-public' }],
'error',
{ accessibility: 'no-public' },
],
/** /**
* https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/member-delimiter-style.md * https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/member-delimiter-style.md

View file

@ -9,6 +9,7 @@
"eslint": "8.23.0", "eslint": "8.23.0",
"eslint-config-airbnb-typescript": "^17.0.0", "eslint-config-airbnb-typescript": "^17.0.0",
"eslint-config-prettier": "^8.5.0", "eslint-config-prettier": "^8.5.0",
"eslint-plugin-diff": "^2.0.1",
"eslint-plugin-import": "^2.26.0", "eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4.2.1", "eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-vue": "^9.4.0" "eslint-plugin-vue": "^9.4.0"