Skip to content

Commit

Permalink
Overhaul react config
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim-W-James committed Oct 16, 2023
1 parent d8ccd8e commit 8699bb4
Show file tree
Hide file tree
Showing 10 changed files with 828 additions and 43 deletions.
10 changes: 10 additions & 0 deletions .prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
plugins: ["prettier-plugin-packagejson"],
semi: true,
singleQuote: false,
trailingComma: "all",
arrowParens: "always",
printWidth: 80,
tabWidth: 2,
useTabs: false,
};
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,16 @@ yarn add --dev @agiledigital/eslint-config \
eslint-plugin-prettier \
eslint-plugin-sonarjs \
eslint-plugin-import \
eslint-plugin-simple-import-sort \
eslint-plugin-filename-rules \
eslint-plugin-jsdoc \
eslint-plugin-tsdoc \
eslint-plugin-no-secrets \
eslint-plugin-prefer-arrow-functions \
eslint-plugin-react \
eslint-plugin-react-hooks \
eslint-plugin-jsx-a11y \
eslint-plugin-react-refresh \
typescript
```

Expand Down
2 changes: 1 addition & 1 deletion base-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const config = {
browser: true,
},
overrides: [],
plugins: ["react", "react-hooks", "jsx-a11y"],
plugins: [],
parser: "@typescript-eslint/parser",
parserOptions: {
project: "./tsconfig.json",
Expand Down
2 changes: 1 addition & 1 deletion base-react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const config: TSESLint.Linter.Config = {
browser: true,
},
overrides: [],
plugins: ["react", "react-hooks", "jsx-a11y"],
plugins: [],
parser: "@typescript-eslint/parser",
parserOptions: {
project: "./tsconfig.json",
Expand Down
164 changes: 163 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"use strict";
// eslint-disable-next-line functional/prefer-immutable-types
const config = {
root: true,
globals: {},
env: {
commonjs: true,
es6: true,
"jest/globals": true,
},
plugins: [
"jest",
Expand All @@ -14,6 +16,12 @@ const config = {
"prettier",
"total-functions",
"import",
"prefer-arrow-functions",
"simple-import-sort",
"filename-rules",
"jsdoc",
"eslint-plugin-tsdoc",
"no-secrets",
],
parser: "@typescript-eslint/parser",
parserOptions: {
Expand All @@ -34,6 +42,7 @@ const config = {
"plugin:prettier/recommended",
"plugin:import/recommended",
"plugin:import/typescript",
"plugin:jsdoc/recommended-typescript",
],
rules: {
"no-template-curly-in-string": ["error"],
Expand All @@ -52,10 +61,162 @@ const config = {
},
],
curly: ["error"],
eqeqeq: ["error", "smart"],
"no-plusplus": ["error", { allowForLoopAfterthoughts: true }],
"no-alert": "error",
"object-shorthand": "warn",
"no-implicit-coercion": "warn",
"prefer-template": "warn",
"@typescript-eslint/prefer-nullish-coalescing": "error",
"@typescript-eslint/ban-ts-comment": [
"error",
{
"ts-expect-error": "allow-with-description",
"ts-ignore": true,
"ts-nocheck": true,
"ts-check": false,
minimumDescriptionLength: 3,
},
],
"@typescript-eslint/no-unused-vars": [
"error",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
caughtErrorsIgnorePattern: "^_",
},
],
"@typescript-eslint/consistent-indexed-object-style": ["error", "record"],
"@typescript-eslint/no-unused-expressions": [
"error",
{
allowShortCircuit: true,
allowTernary: true,
},
],
"@typescript-eslint/no-floating-promises": [
"error",
{ ignoreVoid: true, ignoreIIFE: true },
],
"@typescript-eslint/no-misused-promises": [
"error",
{
checksVoidReturn: {
arguments: false,
attributes: false,
},
},
],
"@typescript-eslint/no-unnecessary-type-arguments": "error",
"@typescript-eslint/naming-convention": [
"warn",
{
selector: "default",
format: ["camelCase"],
leadingUnderscore: "allow",
},
{
selector: "variable",
format: ["camelCase", "UPPER_CASE"],
leadingUnderscore: "allow",
},
{
selector: "parameter",
format: ["camelCase"],
leadingUnderscore: "allow",
},
{
selector: "property",
format: null,
leadingUnderscore: "allow",
},
{
selector: "typeLike",
format: ["PascalCase"],
},
],
"@typescript-eslint/padding-line-between-statements": [
"warn",
{
blankLine: "always",
prev: "*",
next: [
"function",
"interface",
"type",
"try",
"throw",
"case",
"default",
],
},
],
"import/no-extraneous-dependencies": [
"error",
// allow devDependencies to be imported into testing files, etc.
{ devDependencies: ["**/*.{test,spec,story,stories}.{ts,tsx}"] },
],
"import/no-default-export": "error",
"simple-import-sort/imports": "warn",
"simple-import-sort/exports": "warn",
"jsdoc/require-throws": "error",
"jsdoc/check-indentation": "warn",
"jsdoc/no-blank-blocks": "warn",
"jsdoc/require-asterisk-prefix": "warn",
"jsdoc/require-description": "warn",
"jsdoc/sort-tags": "warn",
"jsdoc/check-syntax": "warn",
"jsdoc/tag-lines": ["warn", "never", { startLines: 1 }],
"jsdoc/require-param": ["warn", { checkDestructuredRoots: false }],
"jsdoc/require-jsdoc": [
"warn",
{
publicOnly: true,
require: {
FunctionDeclaration: true,
FunctionExpression: true,
ArrowFunctionExpression: true,
ClassDeclaration: true,
ClassExpression: true,
MethodDefinition: true,
},
contexts: [
"VariableDeclaration",
"TSTypeAliasDeclaration",
// Encourage documenting React prop types
"TSPropertySignature",
],
enableFixer: true,
},
],
// tsdoc checks this syntax instead
"jsdoc/require-hyphen-before-param-description": "off",
"jsdoc/require-returns": "off",
"tsdoc/syntax": "warn",
"prefer-arrow-functions/prefer-arrow-functions": [
"warn",
{
classPropertiesAllowed: true,
disallowPrototype: true,
returnStyle: "unchanged",
},
],
"arrow-body-style": "warn",
"prefer-arrow-callback": [
"warn",
{
allowNamedFunctions: true,
},
],
"filename-rules/match": [2, { ".ts": "camelcase", ".tsx": "pascalcase" }],
"no-secrets/no-secrets": [
"error",
{ ignoreContent: "https", tolerance: 4.2 },
],
},
overrides: [
{
files: ["*.test.ts"],
files: ["*.test.{ts,tsx}"],
rules: {
// We allow tests to interpret/execute effects
"total-functions/no-premature-fp-ts-effects": "off",
Expand All @@ -68,6 +229,7 @@ const config = {
"error",
{ enforcement: "ReadonlyDeep" },
],
"@typescript-eslint/no-floating-promises": "off",
},
},
{
Expand Down
Loading

0 comments on commit 8699bb4

Please sign in to comment.