feat: use lint-staged to run lint before commit (#452)

* chore: remove lintDiff file

* chore: update lock

* chore: add lint script
This commit is contained in:
luhc228 2022-08-25 16:16:43 +08:00 committed by ClarkXia
parent 0345af7202
commit 7ead09710e
4 changed files with 141 additions and 51 deletions

View File

@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npm run lint:diff
npx lint-staged

View File

@ -1,10 +1,12 @@
{
"name": "ice-monorepo",
"private": true,
"workspaces": [
"packages/*"
],
"version": "0.0.1",
"description": "A universal framework based on React",
"author": "ice-admin@alibaba-inc.com",
"license": "MIT",
"homepage": "https://v3.ice.work",
"repository": "ice-lab/ice-next",
"bugs": "https://github.com/ice-lab/ice-next/issues",
"scripts": {
"prepare": "husky install",
"setup": "rm -rf node_modules packages/*/node_modules && pnpm install && pnpm prebundle && pnpm build",
@ -15,20 +17,13 @@
"clean": "rimraf packages/*/esm",
"dependency:check": "esmo ./scripts/dependencyCheck.ts",
"version:check": "esmo ./scripts/versionCheck.ts",
"lint:diff": "esmo ./scripts/lintDiff.ts",
"lint": "eslint --cache --ext .js,.jsx,.ts,.tsx ./",
"lint:fix": "npm run lint -- --fix",
"publish:alpha": "PUBLISH_TYPE=alpha esmo ./scripts/publishPackageWithDistTag.ts",
"publish:beta": "PUBLISH_TYPE=beta esmo ./scripts/publishPackageWithDistTag.ts",
"publish:release": "PUBLISH_TYPE=release VERSION_PREFIX=rc esmo ./scripts/publishPackageWithDistTag.ts",
"cov": "vitest run --coverage",
"test": "vitest"
},
"author": "ice-admin@alibaba-inc.com",
"license": "MIT",
"repository": "ice-lab/ice-next",
"bugs": "https://github.com/ice-lab/ice-next/issues",
"homepage": "https://v3.ice.work",
"devDependencies": {
"@applint/spec": "^1.2.3",
"@commitlint/cli": "^16.3.0",
@ -55,6 +50,7 @@
"husky": "^7.0.4",
"ice-npm-utils": "^3.0.2",
"jsdom": "^20.0.0",
"lint-staged": "^13.0.3",
"prettier": "^2.7.1",
"puppeteer": "^13.7.0",
"react": "^18.2.0",
@ -65,5 +61,8 @@
"typescript": "^4.7.4",
"vitest": "^0.15.2"
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": "eslint --cache --fix"
},
"packageManager": "pnpm@7.2.1"
}

View File

@ -29,6 +29,7 @@ importers:
husky: ^7.0.4
ice-npm-utils: ^3.0.2
jsdom: ^20.0.0
lint-staged: ^13.0.3
prettier: ^2.7.1
puppeteer: ^13.7.0
react: ^18.2.0
@ -64,6 +65,7 @@ importers:
husky: 7.0.4
ice-npm-utils: 3.0.2
jsdom: 20.0.0
lint-staged: 13.0.3
prettier: 2.7.1
puppeteer: 13.7.0
react: 18.2.0
@ -7413,7 +7415,6 @@ packages:
engines: {node: '>=8'}
dependencies:
type-fest: 0.21.3
dev: false
/ansi-html-community/0.0.8:
resolution: {integrity: sha512-1APHAyr3+PCamwNw3bXCPp4HFLONZt/yIH0sZp0/469KWNTEy+qN5jQ3GVX6DMZ1UXAi34yVwtTeaG/HpBuuzw==}
@ -8382,6 +8383,22 @@ packages:
optionalDependencies:
'@colors/colors': 1.5.0
/cli-truncate/2.1.0:
resolution: {integrity: sha512-n8fOixwDD6b/ObinzTrp1ZKFzbgvKZvuz/TvejnLn1aQfC6r52XEx85FmuC+3HI+JM7coBRXUvNqEU2PHVrHpg==}
engines: {node: '>=8'}
dependencies:
slice-ansi: 3.0.0
string-width: 4.2.3
dev: true
/cli-truncate/3.1.0:
resolution: {integrity: sha512-wfOBkjXteqSnI59oPcJkcPl/ZmwvMMOj340qUIY1SKZCv0B9Cf4D4fAucRkIKQmsIuYK3x1rrgU7MeGRruiuiA==}
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
dependencies:
slice-ansi: 5.0.0
string-width: 5.1.2
dev: true
/cli-width/3.0.0:
resolution: {integrity: sha512-FxqpkPPwu1HjuN93Omfm4h8uIanXofW0RxVEW3k5RKx+mJJYSthzNhp32Kzxxy3YAEZ/Dc/EWN1vZRY0+kOhbw==}
engines: {node: '>= 10'}
@ -8465,6 +8482,10 @@ packages:
/colorette/2.0.16:
resolution: {integrity: sha512-hUewv7oMjCp+wkBv5Rm0v87eJhq4woh5rSR+42YSQJKecCqgIqNkZ6lAlQms/BwHPJA5NKMRlpxPRv0n8HQW6g==}
/colorette/2.0.19:
resolution: {integrity: sha512-3tlv/dIP7FWvj3BsbHrGLJ6l/oKh1O3TcgBqMn+yyCagOxc23fyzDS6HypQbgxWbkpDnf52p1LuR4eWDQ/K9WQ==}
dev: true
/combine-promises/1.1.0:
resolution: {integrity: sha512-ZI9jvcLDxqwaXEixOhArm3r7ReIivsXkpbyEWyeOhzz1QS0iSgBPnWvEqvIQtYyamGCYA88gFhmUrs9hrrQ0pg==}
engines: {node: '>=10'}
@ -8503,6 +8524,11 @@ packages:
engines: {node: ^12.20.0 || >=14}
dev: false
/commander/9.4.0:
resolution: {integrity: sha512-sRPT+umqkz90UA8M1yqYfnHlZA7fF6nSphDtxeywPZ49ysjxDQybzk13CL+mXekDRG92skbcqCLVovuCusNmFw==}
engines: {node: ^12.20.0 || >=14}
dev: true
/common-path-prefix/3.0.0:
resolution: {integrity: sha512-QE33hToZseCH3jS0qN96O/bSh3kaw/h+Tq7ngyY9eWDUnTlTNUyqfqvCXioLe5Na5jFsL78ra/wuBU4iuEgd4w==}
dev: false
@ -12341,6 +12367,11 @@ packages:
resolution: {integrity: sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==}
engines: {node: '>=8'}
/is-fullwidth-code-point/4.0.0:
resolution: {integrity: sha512-O4L094N2/dZ7xqVdrXhh9r1KODPJpFms8B5sGdJLPy664AgvXsreZUyCQQNItZRDlYug4xStLjNp/sz3HvBowQ==}
engines: {node: '>=12'}
dev: true
/is-generator-function/1.0.10:
resolution: {integrity: sha512-jsEjy9l3yiXEQ+PsXdmBwEPcOxaXWLspKdplFUVI9vq1iZgIekeC0L167qeu86czQaxed3q/Uzuw0swL0irL8A==}
engines: {node: '>= 0.4'}
@ -12862,6 +12893,48 @@ packages:
/lines-and-columns/1.2.4:
resolution: {integrity: sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==}
/lint-staged/13.0.3:
resolution: {integrity: sha512-9hmrwSCFroTSYLjflGI8Uk+GWAwMB4OlpU4bMJEAT5d/llQwtYKoim4bLOyLCuWFAhWEupE0vkIFqtw/WIsPug==}
engines: {node: ^14.13.1 || >=16.0.0}
hasBin: true
dependencies:
cli-truncate: 3.1.0
colorette: 2.0.19
commander: 9.4.0
debug: 4.3.4
execa: 6.1.0
lilconfig: 2.0.5
listr2: 4.0.5
micromatch: 4.0.5
normalize-path: 3.0.0
object-inspect: 1.12.2
pidtree: 0.6.0
string-argv: 0.3.1
yaml: 2.1.1
transitivePeerDependencies:
- enquirer
- supports-color
dev: true
/listr2/4.0.5:
resolution: {integrity: sha512-juGHV1doQdpNT3GSTs9IUN43QJb7KHdF9uqg7Vufs/tG9VTzpFphqF4pm/ICdAABGQxsyNn9CiYA3StkI6jpwA==}
engines: {node: '>=12'}
peerDependencies:
enquirer: '>= 2.3.0 < 3'
peerDependenciesMeta:
enquirer:
optional: true
dependencies:
cli-truncate: 2.1.0
colorette: 2.0.19
log-update: 4.0.0
p-map: 4.0.0
rfdc: 1.3.0
rxjs: 7.5.5
through: 2.3.8
wrap-ansi: 7.0.0
dev: true
/loader-runner/4.3.0:
resolution: {integrity: sha512-3R/1M+yS3j5ou80Me59j7F9IMs4PXs3VqRrm0TU3AbKPxlmpoY1TNscJV/oGJXo8qCatFGTfDbY6W6ipGOYXfg==}
engines: {node: '>=6.11.5'}
@ -12962,6 +13035,16 @@ packages:
is-unicode-supported: 0.1.0
dev: true
/log-update/4.0.0:
resolution: {integrity: sha512-9fkkDevMefjg0mmzWFBW8YkFP91OrizzkW3diF7CpG+S2EYdy4+TVfGwz1zeF8x7hCx1ovSPTOE9Ngib74qqUg==}
engines: {node: '>=10'}
dependencies:
ansi-escapes: 4.3.2
cli-cursor: 3.1.0
slice-ansi: 4.0.0
wrap-ansi: 6.2.0
dev: true
/loose-envify/1.4.0:
resolution: {integrity: sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==}
hasBin: true
@ -13944,6 +14027,12 @@ packages:
resolution: {integrity: sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==}
engines: {node: '>=8.6'}
/pidtree/0.6.0:
resolution: {integrity: sha512-eG2dWTVw5bzqGRztnHExczNxt5VGsE6OwTeCG3fdUf9KBsZzO3R5OIIIzWR+iZA0NtZ+RDVdaoE2dK1cn6jH4g==}
engines: {node: '>=0.10'}
hasBin: true
dev: true
/pify/4.0.1:
resolution: {integrity: sha512-uB80kBFb/tfd68bVleG9T5GGsGPjJrLAUpR5PZIrhBnIaRTQRjqdJSsIKkOP6OAIFbj7GOrcudc5pNjZ+geV2g==}
engines: {node: '>=6'}
@ -16579,6 +16668,10 @@ packages:
resolution: {integrity: sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==}
engines: {iojs: '>=1.0.0', node: '>=0.10.0'}
/rfdc/1.3.0:
resolution: {integrity: sha512-V2hovdzFbOi77/WajaSMXk2OLm+xNIeQdMMuB7icj7bk6zi2F8GGAxigcnDFpJHbNyNcgyJDiP+8nOrY5cZGrA==}
dev: true
/rimraf/2.6.3:
resolution: {integrity: sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==}
hasBin: true
@ -16988,6 +17081,15 @@ packages:
resolution: {integrity: sha512-3dOsAHXXUkQTpOYcoAxLIorMTp4gIQr5IW3iVb7A7lFIp0VHhnynm9izx6TssdrIcVIESAlVjtnO2K8bg+Coew==}
engines: {node: '>=12'}
/slice-ansi/3.0.0:
resolution: {integrity: sha512-pSyv7bSTC7ig9Dcgbw9AuRNUb5k5V6oDudjZoMBSr13qpLBG7tB+zgCkARjq7xIUgdz5P1Qe8u+rSGdouOOIyQ==}
engines: {node: '>=8'}
dependencies:
ansi-styles: 4.3.0
astral-regex: 2.0.0
is-fullwidth-code-point: 3.0.0
dev: true
/slice-ansi/4.0.0:
resolution: {integrity: sha512-qMCMfhY040cVHT43K9BFygqYbUPFZKHOg7K73mtTWJRb8pyP3fzf4Ixd5SzdEJQ6MRUg/WBnOLxghZtKKurENQ==}
engines: {node: '>=10'}
@ -16997,6 +17099,14 @@ packages:
is-fullwidth-code-point: 3.0.0
dev: true
/slice-ansi/5.0.0:
resolution: {integrity: sha512-FC+lgizVPfie0kkhqUScwRu1O/lF6NOgJmlCgK+/LYxDCTk8sGelYaHDhFcDN+Sn3Cv+3VSa4Byeo+IMCzpMgQ==}
engines: {node: '>=12'}
dependencies:
ansi-styles: 6.1.0
is-fullwidth-code-point: 4.0.0
dev: true
/sockjs/0.3.24:
resolution: {integrity: sha512-GJgLTZ7vYb/JtPSSZ10hsOYIvEYsjbNU+zPdIHcUaWVNUEPivzxku31865sSSud0Da0W4lEeOPlmw93zLQchuQ==}
dependencies:
@ -17160,6 +17270,11 @@ packages:
engines: {node: '>=10.0.0'}
dev: false
/string-argv/0.3.1:
resolution: {integrity: sha512-a1uQGz7IyVy9YwhqjZIZu1c8JO8dNIe20xBmSS6qu9kv++k3JGzCVmprbNN5Kn+BgzD5E7YYwg1CcjuJMRNsvg==}
engines: {node: '>=0.6.19'}
dev: true
/string-convert/0.2.1:
resolution: {integrity: sha512-u/1tdPl4yQnPBjnVrmdLo9gtuLvELKsAoRapekWggdiQNvvvum+jYF329d84NAa660KQw7pB2n36KrIKVoXa3A==}
dev: false
@ -17956,7 +18071,6 @@ packages:
/type-fest/0.21.3:
resolution: {integrity: sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w==}
engines: {node: '>=10'}
dev: false
/type-fest/0.6.0:
resolution: {integrity: sha512-q+MB8nYR1KDLrgr4G5yemftpMC7/QLqVndBmEEdqzmNj5dcFOO4Oo8qlwZE3ULT3+Zim1F8Kq4cBnikNhlCMlg==}
@ -19168,6 +19282,15 @@ packages:
engines: {node: '>=0.10.0'}
dev: true
/wrap-ansi/6.2.0:
resolution: {integrity: sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==}
engines: {node: '>=8'}
dependencies:
ansi-styles: 4.3.0
string-width: 4.2.3
strip-ansi: 6.0.1
dev: true
/wrap-ansi/7.0.0:
resolution: {integrity: sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==}
engines: {node: '>=10'}
@ -19275,6 +19398,11 @@ packages:
resolution: {integrity: sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg==}
engines: {node: '>= 6'}
/yaml/2.1.1:
resolution: {integrity: sha512-o96x3OPo8GjWeSLF+wOAbrPfhFOGY0W00GNaxCDv+9hkcDJEnev1yh8S7pgHF0ik6zc8sQLuL8hjHjJULZp8bw==}
engines: {node: '>= 14'}
dev: true
/yargs-parser/20.2.9:
resolution: {integrity: sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w==}
engines: {node: '>=10'}

View File

@ -1,37 +0,0 @@
import { execSync } from 'child_process';
import { ESLint } from 'eslint';
import chalk from 'chalk';
const GIT_DIFF = 'git diff --cached --diff-filter=ACMR --name-only';
(async () => {
const linter = new ESLint();
// file level
const fileList = execSync(GIT_DIFF).toString().split('\n');
// ignore file which is not js/jsx/ts/tsx
const lintFileList = (await Promise.all(fileList
.map(async (file) => !!file && (/\.(j|t)sx?$/g.test(file) && !(await linter.isPathIgnored(file)) && file))))
.filter(Boolean);
if (!lintFileList.length) {
console.log(chalk.green('no file should be lint.'));
return;
}
console.log(chalk.green(lintFileList.join('\n')));
console.log();
console.log(chalk.green('above file should be lint.'));
const lintResults = await linter.lintFiles(lintFileList);
const Formatter = await linter.loadFormatter();
console.log(Formatter.format(lintResults));
const error = ESLint.getErrorResults(lintResults);
if (error.length > 0) {
process.exit(1);
} else {
console.log(chalk.green('lint successfully.'));
}
})().catch((error) => {
console.trace(error);
process.exit(1);
});