A reusable configuration package that streamlines linting for staged files, ensuring code quality and formatting with tools like ESLint, Prettier, and TypeScript. It simplifies setup, promotes consistency across projects, and enforces best practices before commits, making it an essential tool for modern development workflows.
To use this Lint-Staged configuration in your project, simply install it as a dev dependency:
With npm:
npm install --save-dev lint-staged @commencis/lint-staged-configWith yarn:
yarn add --dev lint-staged @commencis/lint-staged-configWith pnpm:
pnpm add --save-dev lint-staged @commencis/lint-staged-configInstall dependencies
npm install --save-dev huskyAdd your custom script into your `package.json``
"scripts":{
"precommit": "lint-staged"
}Initialize husky with npx husky init and create your ./husky/pre-commit hook as follows:
pnpm run precommit
# Use npm or yarn as per your choice (replace 'pnpm' accordingly)-
baseConfig: Includes Prettier formatting forjsonandmdfiles. -
typescriptConfig: Extends baseConfig with linting commands for TypeScript using ESLint and Prettier. -
reactConfig: Builds on typescriptConfig and adds style-related linting commands. -
reactNativeConfig: Extends typescriptConfig for React Native projects. -
nextConfig: Extends typescriptConfig with style-related linting for Next.js projects. -
vueConfig: Extends typescriptConfig with support for Vue files and style-related linting.
The
GLOBSandCOMMANDSobjects are also exported to allow consistent and customizable overrides.
Once installed, you can reference this configuration in your project's Lint-Staged configuration file, typically named lint-staged.config.js.
To use ESM syntax, ensure your
package.jsonincludes"type": "module". Otherwise, use the.mjsextension for ESM files or stick to CommonJS syntax withrequire('@commencis/lint-staged-config').
Use the default configuration as-is:
export { typescriptConfig as default } from '@commencis/lint-staged-config';Customize the configuration by extending it:
import { reactConfig } from '@commencis/lint-staged-config';
export default {
...reactConfig,
};Add or override specific commands to fit your project’s needs:
import { reactConfig } from '@commencis/lint-staged-config';
export default {
...reactConfig,
[GLOBS.MDX]: ['markdownlint-cli2 --fix'],
'package.json': 'sort-package-json',
'*.test.ts(x)': 'jest --bail --findRelatedTests',
};We welcome contributions to improve this package. Feel free to open issues or pull requests to suggest enhancements or report any issues.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
© Commencis, 2024. All rights reserved.