0.16.5 • Published 1 month ago

eslint-config-rel1cx v0.16.5

Weekly downloads
-
License
MIT
Repository
-
Last release
1 month ago

eslint-config-rel1cx

An ESLint config that self-adapting to project dependencies and TypeScript configuration.

npm install --save-dev eslint-config-rel1cx eslint

pnpm add --save-dev eslint-config-rel1cx 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.

// .eslintrc.js
module.exports = {
  extends: "rel1cx",
};

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.

// .eslintrc.js
const { createConfig } = require("eslint-config-rel1cx/lib/createConfig");

module.exports = createConfig();

Features

// .eslintrc.js
const { createConfig } = require("eslint-config-rel1cx/lib/createConfig");

module.exports = createConfig({
  incrementalAdoption: true,
});

You like all the features eslint-config-rel1cx 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.

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-rel1cx/lib/createConfig");

module.exports = createConfig({
  enableJavaScriptSpecificRulesInTypeScriptProject: true,
});

Examples

const { createConfig } = require("eslint-config-rel1cx/lib/createConfig");
const { getDependencies } = require("eslint-config-rel1cx/lib/getDependencies");
const {
  createTypeScriptOverride,
} = require("eslint-config-rel1cx/lib/overrides/typescript");

const dependencies = getDependencies();

const customTypescriptOverride = createTypeScriptOverride({
  ...dependencies,
  rules: {
    // here goes anything that applies **exclusively** to typescript files based on the `files` glob pattern also exported from ../overrides/typescript
    "@typescript-eslint/explicit-module-boundary-types": "warn", // downgrading the default from "error" to "warn"
  },
});

module.exports = createConfig({
  overrides: [customTypescriptOverride],
});
const { createConfig } = require("eslint-config-rel1cx/lib/createConfig");
const { getDependencies } = require("eslint-config-rel1cx/lib/getDependencies");
const {
  createReactOverride,
} = require("eslint-config-rel1cx/lib/overrides/react");

const dependencies = getDependencies();

const customReactOverride = createReactOverride({
  ...dependencies,
  rules: {
    "unicorn/no-abusive-eslint-disable": "off",
  },
});

module.exports = createConfig({
  overrides: [customReactOverride],
});
const { createConfig } = require("eslint-config-rel1cx/lib/createConfig");
const { getDependencies } = require("eslint-config-rel1cx/lib/getDependencies");
const {
  createReactOverride,
} = require("eslint-config-rel1cx/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],
});
const { getDependencies } = require("eslint-config-rel1cx/lib/getDependencies");
const {
  files,
  parser,
  defaultSettings,
} = require("eslint-config-rel1cx/lib/overrides/react");

const dependencies = getDependencies();

const myReactOverride = {
  // using the internal react glob pattern
  files,
  // using the internal default react parser
  parser,
  // defining your custom rules
  rules: {
    "react/react-in-jsx-scope": "warn",
  },
  // using the default settings
  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.

  • React
  • TypeScript
  • TailwindCSS
  • Node.js
  • NestJS (with TypeScript)

Customization

All rulesets and overrides are created through functions accepting an object matching this schema:

interface Project {
  /**
   * whether `@types/node` is present
   */
  hasNodeTypes: boolean;
  /**
   * whether `@nestjs/core` is present
   */
  hasNest: boolean;
  typescript: {
    /**
     * whether `typescript` is present
     */
    hasTypeScript: boolean;
    /**
     * the installed version
     */
    version: string;
    /**
     * your tsConfig; used to detect feature availability
     */
    config?: object;
  };
  react: {
    /**
     * whether any flavour of react is present
     */
    hasReact: boolean;
    /**
     * whether `preact` is present
     * currently without effect
     */
    isPreact: boolean;
    /**
     * the installed version
     */
    version: string;
  };
  /**
   * your custom rules on top
   */
  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-rel1cx/lib/overrides/typescript')
  • const { createReactOverride } = require('eslint-config-rel1cx/lib/overrides/react')

Please note that the test override should always come last.

Rulesets

  • const { createEslintCoreRules } = require('eslint-config-rel1cx/lib/plugins/eslint-core')
  • const { createImportRules } = require('eslint-config-rel1cx/lib/plugins/import')
  • const { createPromiseRules } = require('eslint-config-rel1cx/lib/plugins/promise')
  • const { createSonarjsRules } = require('eslint-config-rel1cx/lib/plugins/sonarjs')
  • const { createUnicornRules } = require('eslint-config-rel1cx/lib/plugins/unicorn')

Examples

Custom TypeScript override to disable a rule

const { createConfig } = require("eslint-config-rel1cx/lib/createConfig");
const {
  createTypeScriptOverride,
} = require("eslint-config-rel1cx/lib/overrides/typescript");
const packageJson = require("./package.json");

// since `createTypeScriptOverride` is entirely configurable, we need to inform it about its environment
const tsOverrideConfig = {
  react: {
    hasReact: true,
  },
  rules: {
    "@typescript-eslint/ban-ts-comment": "off",
  },
  typescript: {
    hasTypeScript: true,
    // sync with package.json should you upgrade TS
    version: packageJson.dependencies.typescript,
  },
};

// solely an override for TS
const tsOverride = createTypeScriptOverride(tsOverrideConfig);

// pass it into createConfig as array as it will be merged with the other overrides
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

0.16.4

1 month ago

0.16.5

1 month ago

0.16.3

1 month ago

0.16.2

1 month ago

0.16.1

1 month ago

0.16.0

2 months ago

0.15.9

2 months ago

0.15.8

2 months ago

0.15.7

2 months ago

0.15.6

2 months ago

0.15.4

2 months ago

0.15.5

2 months ago

0.15.3

2 months ago

0.15.2

3 months ago

0.15.0

3 months ago

0.14.5

3 months ago

0.14.4

3 months ago

0.14.3

3 months ago

0.14.2

3 months ago

0.14.1

3 months ago

0.14.0

4 months ago

0.13.0

4 months ago

0.12.290

4 months ago

0.12.280

4 months ago

0.12.271

4 months ago

0.12.270

4 months ago

0.12.250

4 months ago

0.12.260

4 months ago

0.12.240

4 months ago

0.12.230

4 months ago

0.12.220

4 months ago

0.12.200

5 months ago

0.12.210

5 months ago

0.12.190

5 months ago

0.12.180

5 months ago

0.12.170

5 months ago

0.12.160

5 months ago

0.12.150

5 months ago

0.12.130

5 months ago

0.12.120

5 months ago

0.12.110

5 months ago

0.12.100

5 months ago

0.12.92

5 months ago

0.12.82

5 months ago

0.12.72

5 months ago

0.12.70

5 months ago

0.12.60

5 months ago

0.12.50

6 months ago

0.12.42

6 months ago

0.12.41

6 months ago

0.12.3

6 months ago