
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
@bassist/eslint-config
Advanced tools
A modern flat ESLint configuration for ESLint, crafted by @chengpeiquan .
A modern flat ESLint configuration for ESLint, crafted by @chengpeiquan.
Using this ESLint configuration only requires three steps:
This quick guide helps you get up and running without missing key steps 🚀 .
Install the package with your favorite package manager:
npm install -D eslint @bassist/eslint-config
Note: Requires ESLint >= 9.0.0
, and TypeScript >= 5.0.0
.
If you’re using pnpm, consider adding a .npmrc
file to your project root with the following settings to handle peer dependencies more smoothly:
shamefully-hoist=true
auto-install-peers=true
For ESLint v8 users, refer to the legacy (unmaintained) package: @bassist/eslint.
Create an eslint.config.js
file at the project root:
// eslint.config.js
import { imports, typescript } from '@bassist/eslint-config'
// export an array of configuration objects
export default [...imports, ...typescript]
Then add "type": "module"
to your package.json
:
{
"type": "module",
"scripts": {
"lint": "eslint src",
"lint:inspector": "npx @eslint/config-inspector"
}
}
Run npm run lint
to lint your code, or npm run lint:inspector
to visualize your ESLint config at localhost:7777.
For typescript file type (e.g.
eslint.config.ts
), requires additional setup .
# Runtime typescript and ESM support for Node.js
npm install -D jiti
For enhanced type safety, use defineFlatConfig
:
// @ts-check
import { defineFlatConfig, imports, vue } from '@bassist/eslint-config'
export default defineFlatConfig([
...imports,
...vue,
// Add more custom configurations
{
// Provide a name for each configuration so that
// it can be clearly displayed in the visualizer
// when running `npm run lint:inspector`.
name: 'my-custom-rule/vue',
rules: {
// e.g. By default, this rule is `off`
'vue/component-tags-order': 'error',
},
ignores: ['examples'],
},
])
Enable automatic linting and fixing in VS Code by adding the following to your workspace settings:
{
"editor.formatOnSave": true,
"eslint.useFlatConfig": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "always",
"source.fixAll.prettier": "always"
}
}
Define ESLint configurations with optional Prettier and Tailwind CSS integration.
The API type declaration:
/**
* Define the ESLint configuration with optional Prettier integration.
*
* @param configs The base ESLint configurations.
* @param options - Options for defining the configuration.
*
* @returns The final ESLint configuration array.
*/
declare const defineFlatConfig: (
configs: FlatESLintConfig[],
options?: DefineFlatConfigOptions,
) => FlatESLintConfig[]
The options type declaration:
interface DefineFlatConfigOptions {
/**
* Specifies the working directory for loading the `.prettierrc`
* configuration.
*
* The config file should be in JSON format.
*
* @default process.cwd()
*/
cwd?: string
/**
* If `prettierEnabled` is set to `false`, all Prettier-related rules and
* configurations will be ignored, even if `prettierRules` are provided.
*
* @default true
*/
prettierEnabled?: boolean
/**
* By default, this will read `.prettierrc` from the current working
* directory, and the `.prettierrc` file must be written in JSON format.
*
* If you are not using a config file with JSON content, or a different config
* file name, you can convert it to JSON rules and pass it in.
*
* After reading the custom configuration, it will be merged with the default
* ESLint rules.
*
* @see https://prettier.io/docs/configuration.html
*/
prettierRules?: PartialPrettierExtendedOptions
/**
* Tailwindcss rules are enabled by default. If they interfere with your
* project, you can disable them with this option.
*
* @default true
*/
tailwindcssEnabled?: boolean
/**
* If you need to override the configuration, you can pass the corresponding
* options.
*
* If you want to merge configurations, you can import
* `defaultTailwindcssSettings`, merge them yourself, and then pass the result
* in.
*
* If an empty object `{}` is passed, the default settings will be used.
*/
tailwindcssSettings?: TailwindcssSettings
}
createGetConfigNameFactory
is a flexible tool function for generating ESLint configuration naming tools. It helps you quickly splice configuration names, ensure consistent namespaces, and facilitate the organization and management of complex rule sets.
The API type declaration:
/**
* A flexible tool function for generating ESLint configuration naming tools. It
* helps you quickly splice configuration names, ensure consistent namespaces,
* and facilitate the organization and management of complex rule sets.
*
* @param prefix - A string representing the prefix for your configuration
* names.
* @returns A function that concatenates the provided name segments with the
* given prefix.
*/
declare const createGetConfigNameFactory: (
prefix: string,
) => (...names: string[]) => string
Usage:
import {
createGetConfigNameFactory,
defineFlatConfig,
} from '@bassist/eslint-config'
const getConfigName = createGetConfigNameFactory('my-prefix')
export default defineFlatConfig([
{
name: getConfigName('ignore'), // --> `my-prefix/ignore`
ignores: ['**/dist/**', '**/.build/**', '**/CHANGELOG.md'],
},
])
Why Use This?
This utility is especially helpful when building reusable ESLint configurations or maintaining a well-structured ruleset for complex projects.
These are mainly the ones I use frequently. If you need any additions, welcome PR!
Formatting rules are enabled by default and not exported externally. Please pass custom configuration via options
of defineFlatConfig API .
.prettierrc
and .prettierignore
are read and added to ESLint rules.tailwind.config.js
is passed as the Tailwind CSS configuration file.--ext
CLI option is no longer available (#16991).Please refer to CHANGELOG for details.
MIT License © 2023-PRESENT chengpeiquan
FAQs
A modern flat ESLint configuration for ESLint, crafted by @chengpeiquan .
The npm package @bassist/eslint-config receives a total of 297 weekly downloads. As such, @bassist/eslint-config popularity was classified as not popular.
We found that @bassist/eslint-config demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.