Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ESLint #197

Open
tukusejssirs opened this issue Dec 16, 2022 · 2 comments
Open

Use ESLint #197

tukusejssirs opened this issue Dec 16, 2022 · 2 comments
Assignees
Labels
enhancement New feature or request infrastructure Anything related to the surrounding tools and infrastructure

Comments

@tukusejssirs
Copy link
Contributor

tukusejssirs commented Dec 16, 2022

ESLint is used to define some style rules, as well as it checks some common code mistakes. ESLint statically analyses the code to quickly find problems.

@tukusejssirs tukusejssirs added this to the Backlog milestone Dec 16, 2022
@MRIIOT
Copy link
Contributor

MRIIOT commented Dec 16, 2022

This is a dev behavior change.
Push .eslintrc file once created.

@tukusejssirs
Copy link
Contributor Author

This is my current ESLint config. I don’t want to force anyone my preferences, therefore @bburns, we could discuss individual configs and decide on what will be used in l99 repo. Also, I prefer using JSON file (.eslintrc.json) instead of JS, however, I don’t mind using a JS file instead. I commented on som config in this issue. Also note that until we use Nx, we need to remove all config that mentions nx or nrwl.

.eslintrc.json
{
   "extends": [
      "eslint:recommended",
      "plugin:import/recommended"
   ],
   "overrides": [
      {
         "files": [
            "*.ts",
            "*.tsx",
            "*.js",
            "*.jsx",
            "*.cjs",
            "*.mjs"
         ],
         "rules": {
            "@nrwl/nx/enforce-module-boundaries": [
               "error",
               {
                  "allow": [],
                  "depConstraints": [
                     {
                        "onlyDependOnLibsWithTags": [
                           "*"
                        ],
                        "sourceTag": "*"
                     }
                  ],
                  "enforceBuildableLibDependency": true
               }
            ]
         }
      },
      {
         "extends": [
            "plugin:@typescript-eslint/eslint-recommended",
            "plugin:@typescript-eslint/recommended"
         ],
         "files": [
            "*.ts",
            "*.tsx"
         ],
         "rules": {
            "@typescript-eslint/array-type": ["error", {"default": "array"}],
            "@typescript-eslint/class-literal-property-style": ["error", "getters"],
            "@typescript-eslint/explicit-function-return-type": "error",
            "@typescript-eslint/explicit-member-accessibility": ["error", {"accessibility": "no-public"}],
            "@typescript-eslint/explicit-module-boundary-types": "error",
            "@typescript-eslint/indent": [
               "error",
               "tab",
               {
                  "ArrayExpression": 1,
                  "FunctionDeclaration": {
                     "parameters": "first"
                  },
                  "ImportDeclaration": 1,
                  "ObjectExpression": 1,
                  "SwitchCase": 1,
                  "VariableDeclarator": "first",
                  "flatTernaryExpressions": false,
                  "ignoredNodes": [
                     "FunctionExpression > .params[decorators.length > 0]",
                     "FunctionExpression > .params > :matches(Decorator, :not(:first-child))",
                     "ClassBody.body > PropertyDefinition[decorators.length > 0] > .key"
                  ]
               }
            ],
            "@typescript-eslint/interface-name-prefix": "off",
            // TODO: Consider either raising `@typescript-eslint/no-confusing-non-null-assertion` to `error` or removing the rule.
            "@typescript-eslint/no-confusing-non-null-assertion": "warn",
            // TODO: Consider changing `@typescript-eslint/no-explicit-any` to `error`.
            "@typescript-eslint/no-explicit-any": "off",
            "@typescript-eslint/no-extra-parens": [
               "error"
            ],
            "@typescript-eslint/no-floating-promises": [
               "error"
            ],
            "@typescript-eslint/no-non-null-assertion": "error",
            // TODO: Configure this config.
            // "@typescript-eslint/no-unused-vars": [
            //    "error",
            //    {
            //       "argsIgnorePattern": "^_",
            //       "ignoreRestSiblings": true
            //    }
            // ],
            "@typescript-eslint/no-use-before-define": "error",
            "@typescript-eslint/parameter-properties": "off",
            "@typescript-eslint/prefer-includes": "error",
            "@typescript-eslint/prefer-optional-chain": "error",
            "@typescript-eslint/prefer-readonly": "error",
            "@typescript-eslint/prefer-regexp-exec": "error",
            "@typescript-eslint/require-array-sort-compare": ["error", {"ignoreStringArrays": true}],
            "@typescript-eslint/return-await": ["error", "always"],
            "no-extra-parens": "off",
            "no-return-await": "off",
            "no-use-before-define": "off"
         }
      },
      {
         "files": [
            "*.js",
            "*.jsx"
         ],
         "rules": {
            "no-extra-parens": ["error"],
            "no-return-await": 2,
            "no-use-before-define": "error"
         }
      }
   ],
   "parser": "@typescript-eslint/parser",
   "parserOptions": {
      "ecmaVersion": 2020,
      "project": "tsconfig.base.json",
      "sourceType": "module"
   },
   "plugins": [
      "@nrwl/nx",
      "@typescript-eslint",
      "@typescript-eslint/eslint-plugin",
      "eslint-plugin-tsdoc",
      // TODO: Consider using these plugins.
      // "simple-import-sort",
      // "import",
      // "jest",
      "sort-keys-custom-order",
      "unicorn"
   ],
   "root": true,
   "rules": {
      "array-bracket-spacing": [
         "error",
         "never"
      ],
      "arrow-body-style": [
         "error",
         "as-needed"
      ],
      "arrow-parens": [
         "error",
         "as-needed"
      ],
      "comma-dangle": [
         "error",
         "never"
      ],
      "comma-spacing": [
         "error",
         {
            "before": false,
            "after": true
         }
      ],
      "computed-property-spacing": [
         "error",
         "never"
      ],
      "curly": "error",
      "for-direction": "error",
      "import/first": "error",
      "import/named": "error",
      "import/newline-after-import": "error",
      "import/no-duplicates": "error",
      "import/no-unresolved": "off",
      "import/no-unused-modules": "error",
      "import/order": [
         "error",
         {
            "alphabetize": {
               "caseInsensitive": true,
               "order": "asc"
            },
            "groups": [
               "builtin",
               "external",
               [
                  "internal",
                  "parent",
                  "sibling",
                  "index"
               ],
               [
                  "object",
                  "type"
               ]
            ],
            "newlines-between": "always"
         }
      ],
      // TODO: Why did I turn `indent` rule off for JS files? If needed look at the following config from old romcal ESLint config.
      // indent: [
      //    'error',
      //    'tab',
      //    {
      //       SwitchCase: 1,
      //       VariableDeclarator: 'first',
      //       FunctionDeclaration: {parameters: 'first'},
      //       ArrayExpression: 1,
      //       ObjectExpression: 1,
      //       ImportDeclaration: 1,
      //       flatTernaryExpressions: false
      //    }
      // ],
      "indent": "off",
      "key-spacing": [
         "error",
         {
            "singleLine": {
               "afterColon": true,
               "beforeColon": false
            },
            "multiLine": {
               "afterColon": true,
               "beforeColon": false
            }
         }
      ],
      "keyword-spacing": [
         "error",
         {
            "after": true,
            "before": true
         }
      ],
      "linebreak-style": ["error", "unix"],
      // TODO: One [this discussion](https://github.com/eslint/eslint/discussions/16142) has a solution, I’d like to enforce newlines before and after multi-line class members (of course, not at the beginning and at the end of the class).
      // "lines-between-class-members": ["error", "always"],
      "max-len": [
         "error",
         {
            "code": 175,
            "ignoreComments": true,
            "ignoreRegExpLiterals": true,
            "ignoreStrings": true,
            "ignoreTemplateLiterals": true,
            "ignoreTrailingComments": true,
            "ignoreUrls": true,
            "tabWidth": 2
         }
      ],
      // TODO: Consider setting `new-cap` to `error`.
      // 'new-cap': 'error',
      "new-cap": "off",
      "no-case-declarations": "off",
      "no-fallthrough": "off",
      "no-lonely-if": "error",
      "no-mixed-spaces-and-tabs": "error",
      "no-new-wrappers": "error",
      "no-multiple-empty-lines": [
         "error",
         {
            "max": 1,
            "maxBOF": 0,
            "maxEOF": 0
         }
      ],
      "no-tabs": [
         "error",
         {
            "allowIndentationTabs": true
         }
      ],
      "no-trailing-spaces": "error",
      // TODO: Consider making `no-unused-vars` to error out, which is enabled by `eslint:recommend`, thus simply remove this rule.
      "no-unused-vars": "off",
      "no-useless-concat": "error",
      "no-var": "error",
      "object-curly-spacing": [
         "error",
         "never"
      ],
      "object-property-newline": [
         "error",
         {
            "allowAllPropertiesOnSameLine": true
         }
      ],
      "padded-blocks": [
         "error",
         "never"
      ],
      "prefer-template": "error",
      "quote-props": [
         "error",
         "as-needed"
      ],
      "quotes": [
         "error",
         "single",
         {
            "allowTemplateLiterals": true,
            "avoidEscape": true
         }
      ],
      "semi": [
         "error",
         "never"
      ],
      "semi-spacing": [
         "error",
         {
            "before": false,
            "after": true
         }
      ],
      "sort-imports": [
         "error",
         {
            "allowSeparatedGroups": true,
            "ignoreCase": true,
            "ignoreDeclarationSort": true,
            "ignoreMemberSort": false,
            "memberSyntaxSortOrder": [
               "none",
               "all",
               "multiple",
               "single"
            ]
         }
      ],
      "sort-keys-custom-order/object-keys": "error",
      "sort-keys-custom-order/type-keys": "error",
      "sort-vars": [
         "error",
         {
            "ignoreCase": true
         }
      ],
      "space-before-blocks": "error",
      "spaced-comment": [
         "error",
         "always"
      ],
      "space-infix-ops": "error",
      "switch-colon-spacing": [
         "error",
         {
            "before": false,
            "after": true
         }
      ],
      "template-curly-spacing": ["error", "never"],
      "tsdoc/syntax": "warn",
      "unicorn/better-regex": "error",
      "unicorn/catch-error-name": [
         "error",
         {
            "name": "e"
         }
      ],
      "unicorn/consistent-destructuring": "error",
      "unicorn/custom-error-definition": "error",
      "unicorn/empty-brace-spaces": "error",
      "unicorn/error-message": "error",
      "unicorn/prefer-module": "error",
      "unicorn/prefer-node-protocol": "error",
      "wrap-regex": "off"
   }
}

@tukusejssirs tukusejssirs removed this from the Backlog milestone Dec 17, 2022
@tukusejssirs tukusejssirs added infrastructure Anything related to the surrounding tools and infrastructure enhancement New feature or request labels Dec 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request infrastructure Anything related to the surrounding tools and infrastructure
Projects
None yet
Development

No branches or pull requests

3 participants