-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automate Linting with Husky and lint-staged to Prevent CI Failures (#896
) This PR addresses the issue where linting was not being automatically executed before commits, despite Husky being installed. The previous setup had Husky installed at v8, but proper pre-commit hooks were not in place to ensure that linting occurred consistently. Since Husky v5, the configuration and usage have changed. For more details, refer to the documentation of Husky. Key changes include: - Adding the missing pre-commit configuration in the .husky folder, and ensure Husky works as expected to automate linting at the pre-commit stage. - Integrating lint-staged to only lint the files that are staged for commit, improving efficiency. With these updates, developers will no longer need to manually run lint checks, as the process will be automated and enforced during the commit phase.
- Loading branch information
1 parent
17c8704
commit 4837c7d
Showing
18 changed files
with
7,023 additions
and
2,365 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# common | ||
**/dist/* | ||
|
||
# sdk | ||
packages/sdk/src/api/yorkie/v1/yorkie_grpc_web_pb.d.ts | ||
packages/sdk/src/api/yorkie/v1/yorkie_pb.d.ts | ||
packages/sdk/src/api/yorkie/v1/resources_grpc_web_pb.d.ts | ||
packages/sdk/src/api/yorkie/v1/resources_pb.d.ts | ||
packages/sdk/test/vitest.d.ts | ||
packages/sdk/lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
module.exports = { | ||
root: true, | ||
plugins: ['prettier', 'jsdoc', '@typescript-eslint'], | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:@typescript-eslint/eslint-recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
], | ||
rules: { | ||
'prettier/prettier': 'error', | ||
'object-shorthand': ['error', 'always'], | ||
'no-unreachable': 'error', | ||
}, | ||
overrides: [ | ||
{ | ||
files: ['**/*.ts', '**/*.tsx'], | ||
parser: '@typescript-eslint/parser', | ||
plugins: ['@typescript-eslint'], | ||
extends: ['plugin:@typescript-eslint/recommended'], | ||
rules: { | ||
'@typescript-eslint/no-non-null-assertion': 'off', | ||
'@typescript-eslint/no-explicit-any': 'off', | ||
'@typescript-eslint/ban-ts-comment': 'off', | ||
'jsdoc/require-jsdoc': [ | ||
'error', | ||
{ | ||
contexts: ['MethodDefinition:not([accessibility="private"])'], | ||
require: { | ||
ClassDeclaration: true, | ||
}, | ||
checkConstructors: false, | ||
enableFixer: false, | ||
}, | ||
], | ||
'@typescript-eslint/naming-convention': [ | ||
'error', | ||
{ | ||
selector: 'variable', | ||
format: ['camelCase', 'PascalCase'], | ||
leadingUnderscore: 'allowDouble', | ||
trailingUnderscore: 'allowDouble', | ||
}, | ||
], | ||
'@typescript-eslint/ban-types': [ | ||
'error', | ||
{ | ||
types: { null: 'Use undefined instead of null' }, | ||
}, | ||
], | ||
'@typescript-eslint/array-type': ['error', { default: 'generic' }], | ||
'@typescript-eslint/no-this-alias': [ | ||
'error', | ||
{ | ||
allowDestructuring: true, | ||
allowedNames: ['node'], | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
npx lint-staged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,6 @@ module.exports = { | |
endOfLine: 'auto', | ||
}, | ||
], | ||
'@next/next/no-html-link-for-pages': 'off', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const { ESLint } = require('eslint'); | ||
const { execSync } = require('child_process'); | ||
const path = require('path'); | ||
|
||
const removeIgnoredFiles = async (files) => { | ||
const eslintIgnorePath = path.resolve('.eslintignore'); // Pointing to the root .eslintignore | ||
const eslint = new ESLint({ ignorePath: eslintIgnorePath }); | ||
|
||
const isIgnored = await Promise.all( | ||
files.map(async (file) => { | ||
const ignored = await eslint.isPathIgnored(file); | ||
return ignored; | ||
}), | ||
); | ||
|
||
const filteredFiles = files.filter((_, i) => !isIgnored[i]); | ||
return filteredFiles; | ||
}; | ||
|
||
module.exports = { | ||
'**/*.ts': async (files) => { | ||
const filesToLint = await removeIgnoredFiles(files); | ||
|
||
if (filesToLint.length > 0) { | ||
const fileArgs = filesToLint.join(' '); | ||
const command = `pnpm exec eslint ${fileArgs} --fix --max-warnings=0 --ext .ts`; | ||
try { | ||
execSync(command, { stdio: 'inherit' }); | ||
process.exit(0); | ||
} catch (error) { | ||
console.error('Linting failed. Commit will be aborted.'); | ||
process.exit(1); | ||
} | ||
} else { | ||
console.log('No eligible files to lint. Skipping lint-staged command.'); | ||
process.exit(0); | ||
} | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.