eslint-plugin-glue v0.3.2
ESLint Plugin Glue
Allows local ESLint Rules written in TypeScript or JavaScript to be available locally within your project.
This means that developers can create their own custom ESLint Plugins within a project and consume them within that project without having to publish or use Symlinks.
Installation
npm install -D @bitovi/eslint-plugin-glue
How to Use
Create an eslint-plugin-glue.config.js
file at the root of your project. This file will export your ESLint Plugins by name, a path to its exported rules, and which TypeScript configuration to use:
// eslint-plugin-glue.config.js
module.exports = {
'my-plugin': {
plugin: 'tools/my-rules',
tsconfig: 'tools/my-rules/tsconfig.json',// (optional)
},
};
This example will check tools/my-rules
for index.ts
or index.js
that exports an ESLint Plugin:
// tools/my-rules/index.ts
import { myCustomRule} from './rules/my-custom-rule';
import { mySecondCustomRule } from './rules/my-second-custom-rule';
module.exports = {
rules: {
'some-custom-rule-name': myCustomRule,
'another-custom-rule-name': mySecondCustomRule,
},
};
Now you can include these rules into your eslint configuration by adding @bitovi/glue
to your plugins and listing which rules you want to use within overrides
:
// .eslintrc
{
"plugins": ["@bitovi/glue"],
"overrides": [
{
"files": ["*.ts"],
"rules": {
"@bitovi/glue/my-plugin/some-custom-rule-name": "error",
"@bitovi/glue/my-plugin/another-custom-rule-name": "warn"
}
}
]
}
Configuration Schema
Listed below is a detailed explaination of how the eslint-plugin-glue
configuration schema affects how you can consume your custom rules:
// eslint-plugin-glue.config.js
module.exports = {
'<plugin-name>': {
plugin: 'path/to/rules/from/root/of/project',
tsconfig: 'path/to/tsconfig/from/root/of/project/tsconfig.json',
},
'<plugin-name-2>': {
plugin: 'path/to/rules/from/root/of/project',
tsconfig: 'path/to/tsconfig/from/root/of/project/tsconfig.json',
},
// ...
};
Configuration schema:
plugin-name
: Used to distinguish each plugin. This allows for plugins to have the same named rules within the same project.plugin
: Path to exported ESLint Plugin from root of project.tsconfig
: Path to TypeScript configuration from root of project (Optional).
This allows you to consume your custom rules exported by your local ESLint Plugins:
// .eslintrc
{
"plugins": ["@bitovi/glue"],
"overrides": [
{
"files": ["..."],
"rules": {
"@bitovi/glue/<plugin-name>/<custom-rule-name>": "...",
"@bitovi/glue/<plugin-name>/<custom-rule-name-2>": "...",
"@bitovi/glue/<plugin-name-2>/<another-custom-rule-name>": "..."
}
}
]
}
ESLint Extention
If you are using VSCode's ESLint extention, you will have to restart your ESLint server whenever you make changes to your ESLint Plugin(s).
You can quickly restart your ESLint server by using the Command Palette and selecting ESLint: Restart ESLint Server
.
Overriding Configuration Path
You can set path to your eslint-plugin-glue
configuration by setting ESLINT_PLUGIN_GLUE_CONFIG_PATH
environment variable.
By default, eslint-plugin-glue configuration is expected to be at the root of your project and to be named eslint-plugin-glue.config.js
.