Skip to content

Commit

Permalink
Complete rules for plugin-import
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena committed Dec 2, 2023
1 parent 9d46601 commit 88b59ee
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 44 deletions.
3 changes: 1 addition & 2 deletions packages/eslint-config/rules/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,7 @@ module.exports = {
// https://jc-verse.github.io/js-style-guide/eslint-base/control-flow#no-duplicate-case
"no-duplicate-case": "error",

// Shadowed by plugin-imports rule
// TODO
// Shadowed by import/no-duplicates
"no-duplicate-imports": "off",

// `else-if` is able to save one line, and also makes the flow more natural.
Expand Down
118 changes: 106 additions & 12 deletions packages/eslint-config/rules/import.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,128 @@
// This section is not completed.
// TODO turn on more rules

module.exports = {
plugins: ["import"],
rules: {
// We use @typescript-eslint/no-import-type-side-effects
"import/consistent-type-specifier-style": "off",

// This rule reports when using esModuleInterop
"import/default": "off",

"import/first": "error",
// Enable if you use Webpack
"import/dynamic-import-chunkname": 0,

"import/export": "error",

"import/exports-last": "off",

"import/extensions": "off",

"import/named": "error",
"import/first": ["error", "absolute-first"],

// Not as useful
// We want the opposite style
"import/group-exports": "off",

"import/max-dependencies": "off",

// Performance
"import/named": "off",

// Performance
"import/namespace": "off",

"import/newline-after-import": "error",
"import/newline-after-import": [
"error",
{ considerComments: true, count: 1, exactCount: true },
],

// Don't do absolute, even when authoring modules directly sent to browsers!
"import/no-absolute-path": [
"error",
{ amd: true, commonjs: true, esmodule: true },
],

// We don't use AMD
"import/no-amd": "error",

// Anonymous functions/classes are already covered by func-names
"import/no-anonymous-default-export": "off",

"import/no-commonjs": "off",

// Performance, and cycles are generally not an issue until they are
"import/no-cycle": "off",

// Please use default export for React components
"import/no-default-export": "off",

"import/no-deprecated": "off",

"import/no-duplicates": [
"error",
{ considerQueryString: true, "prefer-inline": true },
],

"import/no-dynamic-require": "off",

"import/no-empty-named-blocks": "error",

"import/no-absolute-path": "error",
"import/no-extraneous-dependencies": [
"error",
{
bundledDependencies: false,
devDependencies: ["**/*.test.{js,ts,jsx,tsx}"],
optionalDependencies: false,
peerDependencies: true,
},
],

// If you have to do this, it must be for some weird reason
"import/no-import-module-exports": "warn",

"import/no-internal-modules": "off",

// The only reason to use this is when the environment doesn't handle this
// compliantly
"import/no-mutable-exports": "off",

// Performance
"import/no-named-as-default": "off",

// Performance
"import/no-named-as-default-member": "off",

"import/no-named-default": "error",

"import/no-named-export": "off",

"import/no-namespace": "off",

"import/no-duplicates": "error",
"import/no-nodejs-modules": "off",

// This rule doesn't play well with TypeScript + ESM. TS is able to catch
// missing import anyways.
"import/no-unresolved": ["off", { caseSensitive: true, commonjs: true }],
"import/no-relative-packages": "warn",

"import/no-relative-parent-imports": "off",

"import/no-restricted-paths": 0,

"import/no-self-import": "error",

"import/no-unassigned-import": "off",

"import/no-unresolved": "off",

"import/no-unused-modules": 0,

// Going one directory above ensures transpilation doesn't mess with paths
"import/no-useless-path-segments": "off",

// When we use it, it's useful.
"import/no-webpack-loader-syntax": "off",

"import/order": 0,

"import/prefer-default-export": "off",

"import/unambiguous": "off",
},
settings: {
"import/resolver": {
Expand Down
38 changes: 8 additions & 30 deletions packages/eslint-config/rules/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,7 @@ module.exports = {
// https://jc-verse.github.io/js-style-guide/typescript/base#consistent-type-assertions
"@typescript-eslint/consistent-type-assertions": [
"error",
{
assertionStyle: "as",
objectLiteralTypeAssertions: "allow",
},
{ assertionStyle: "as", objectLiteralTypeAssertions: "allow" },
],

// We sometimes allow declaration merging
Expand Down Expand Up @@ -156,9 +153,7 @@ module.exports = {
// https://jc-verse.github.io/js-style-guide/typescript/base#no-empty-interface
"@typescript-eslint/no-empty-interface": [
"error",
{
allowSingleExtends: true,
},
{ allowSingleExtends: true },
],

// https://jc-verse.github.io/js-style-guide/typescript/base#no-explicit-any
Expand Down Expand Up @@ -193,10 +188,7 @@ module.exports = {
// https://jc-verse.github.io/js-style-guide/typescript/base#no-invalid-void-type
"@typescript-eslint/no-invalid-void-type": [
"warn",
{
allowAsThisParameter: false,
allowInGenericTypeArguments: true,
},
{ allowAsThisParameter: false, allowInGenericTypeArguments: true },
],

// We turn off the base rule too
Expand Down Expand Up @@ -259,10 +251,7 @@ module.exports = {
// https://jc-verse.github.io/js-style-guide/typescript/base#no-this-alias
"@typescript-eslint/no-this-alias": [
"warn",
{
allowDestructuring: true,
allowedNames: [],
},
{ allowDestructuring: true, allowedNames: [] },
],

// Deprecated
Expand Down Expand Up @@ -325,10 +314,7 @@ module.exports = {
// https://jc-verse.github.io/js-style-guide/typescript/base#parameter-properties
"@typescript-eslint/parameter-properties": [
"warn",
{
allow: [],
prefer: "class-property",
},
{ allow: [], prefer: "class-property" },
],

// https://jc-verse.github.io/js-style-guide/typescript/base#prefer-as-const
Expand All @@ -346,9 +332,7 @@ module.exports = {
// https://jc-verse.github.io/js-style-guide/typescript/base#prefer-literal-enum-member
"@typescript-eslint/prefer-literal-enum-member": [
"warn",
{
allowBitwiseExpressions: true,
},
{ allowBitwiseExpressions: true },
],

// https://jc-verse.github.io/js-style-guide/typescript/base#prefer-namespace-keyword
Expand All @@ -362,11 +346,7 @@ module.exports = {
// https://jc-verse.github.io/js-style-guide/typescript/base#triple-slash-reference
"@typescript-eslint/triple-slash-reference": [
"error",
{
lib: "never",
path: "never",
types: "prefer-import",
},
{ lib: "never", path: "never", types: "prefer-import" },
],

// We use strict TS options instead.
Expand All @@ -376,9 +356,7 @@ module.exports = {
// https://jc-verse.github.io/js-style-guide/typescript/base#unified-signatures
"@typescript-eslint/unified-signatures": [
"warn",
{
ignoreDifferentlyNamedParameters: false,
},
{ ignoreDifferentlyNamedParameters: false },
],
},
};

0 comments on commit 88b59ee

Please sign in to comment.