eslint-config-relicx
An ESLint config that self-adapting to project dependencies and TypeScript configuration.
npm install --save-dev eslint-config-relicx eslint
pnpm add --save-dev eslint-config-relicx eslint
Setup
Basic
You profit automatically of automatic dependency and feature detection. Due to the nature of ESLint configs however this approach is significantly harder to customize.
module.exports = {
extends: "relicx",
};
Advanced
This showcases the required setup to begin with customizing your config on an advanced level. Please check out the Examples
section below for more details.
const { createConfig } = require("eslint-config-relicx/lib/createConfig");
module.exports = createConfig();
Features
Incremental Adoption
const { createConfig } = require("eslint-config-relicx/lib/createConfig");
module.exports = createConfig({
incrementalAdoption: true,
});
Starting with a blank slate
You like all the features eslint-config-relicx
ships with but you heavily disagree with many rule settings?
Say no more. Simply pass { blankSlate: true }
to createConfig
and you still benefit from automatic dependency detection, the general override setup based on file patterns, but every rule will be set to off
.
This way, you can customize it entirely to your likings without having to create n overrides for rules and or rulesets.
Migrating a codebase to TypeScript
While in the process of migration, you may end up in a situation where you cannot turn on compilerOptions.checkJs
from TypeScript itself due to e.g. builds breaking. However, by default certain rules will be disabled for JavaScript files because they are technically shadowed by TypeScript itself, e.g. no-undef
.
You can opt out of this behaviour by either:
- passing
enableJavaScriptSpecificRulesInTypeScriptProject
as true
to createConfig
- enabling
compilerOptions.checkJs
once you're there
Example:
const { createConfig } = require("eslint-config-relicx/lib/createConfig");
module.exports = createConfig({
enableJavaScriptSpecificRulesInTypeScriptProject: true,
});
Examples
Disabling a specific @typescript-eslint rule
const { createConfig } = require("eslint-config-relicx/lib/createConfig");
const { getDependencies } = require("eslint-config-relicx/lib/getDependencies");
const {
createTypeScriptOverride,
} = require("eslint-config-relicx/lib/overrides/typescript");
const dependencies = getDependencies();
const customTypescriptOverride = createTypeScriptOverride({
...dependencies,
rules: {
"@typescript-eslint/explicit-module-boundary-types": "warn",
},
});
module.exports = createConfig({
overrides: [customTypescriptOverride],
});
Changing a eslint-plugin-unicorn rule specifically for React files
const { createConfig } = require("eslint-config-relicx/lib/createConfig");
const { getDependencies } = require("eslint-config-relicx/lib/getDependencies");
const {
createReactOverride,
} = require("eslint-config-relicx/lib/overrides/react");
const dependencies = getDependencies();
const customReactOverride = createReactOverride({
...dependencies,
rules: {
"unicorn/no-abusive-eslint-disable": "off",
},
});
module.exports = createConfig({
overrides: [customReactOverride],
});
Adding plugins to any override
const { createConfig } = require("eslint-config-relicx/lib/createConfig");
const { getDependencies } = require("eslint-config-relicx/lib/getDependencies");
const {
createReactOverride,
} = require("eslint-config-relicx/lib/overrides/react");
const dependencies = getDependencies();
const customReactOverride = createReactOverride({
...dependencies,
plugins: ["my-fancy-plugin"],
rules: {
"plugin/foo": "warn",
"plugin/bar": "error",
"plugin/baz": "off",
},
});
module.exports = createConfig({
overrides: [customReactOverride],
});
Building your own config with the available exports
const { getDependencies } = require("eslint-config-relicx/lib/getDependencies");
const {
files,
parser,
defaultSettings,
} = require("eslint-config-relicx/lib/overrides/react");
const dependencies = getDependencies();
const myReactOverride = {
files,
parser,
rules: {
"react/react-in-jsx-scope": "warn",
},
settings: defaultSettings,
};
module.exports = {
overrides: [myReactOverride],
rules: {
"no-await-in-loop": "warn",
},
};
What's included?
Everything is dynamically included based on your package.json
and when using TypeScript, your tsconfig.json
.
Rules are selectively applied based on file name patterns.
All rules are commented and link to their docs.
Customization
All rulesets and overrides are created through functions accepting an object
matching this schema:
interface Project {
hasNodeTypes: boolean;
hasNest: boolean;
typescript: {
hasTypeScript: boolean;
version: string;
config?: object;
};
react: {
hasReact: boolean;
isPreact: boolean;
version: string;
};
rules?: object;
}
Available main exports
This list only mentions the exports most people will need. For an exhaustive
list, check out the source.
Overrides
const { createTypeScriptOverride } = require('eslint-config-relicx/lib/overrides/typescript')
const { createReactOverride } = require('eslint-config-relicx/lib/overrides/react')
Please note that the test override should always come last.
Rulesets
const { createEslintCoreRules } = require('eslint-config-relicx/lib/plugins/eslint-core')
const { createImportRules } = require('eslint-config-relicx/lib/plugins/import')
const { createPromiseRules } = require('eslint-config-relicx/lib/plugins/promise')
const { createSonarjsRules } = require('eslint-config-relicx/lib/plugins/sonarjs')
const { createUnicornRules } = require('eslint-config-relicx/lib/plugins/unicorn')
Examples
Custom TypeScript override to disable a rule
const { createConfig } = require("eslint-config-relicx/lib/createConfig");
const {
createTypeScriptOverride,
} = require("eslint-config-relicx/lib/overrides/typescript");
const packageJson = require("./package.json");
const tsOverrideConfig = {
react: {
hasReact: true,
},
rules: {
"@typescript-eslint/ban-ts-comment": "off",
},
typescript: {
hasTypeScript: true,
version: packageJson.dependencies.typescript,
},
};
const tsOverride = createTypeScriptOverride(tsOverrideConfig);
module.exports = createConfig({ overrides: [tsOverride] });
Meta
This project follows semver.
THIRD-PARTY-LICENSE
This project uses code from following third-party projects:
Licenses are list in THIRD-PARTY-LICENSE