ryee-dev / cra.ts

A custom TypeScript-based create-react-app boilerplate including all the necessary linting files & encourages up-to-date best-practices.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Typescript Project Config

Additional Dependencies

Package Name Description
eslint-config-prettier Turns off all rules that are unnecessary or might conflict with Prettier.
@typescript-eslint/parser An ESLint-specific parser which leverages typescript-estree and is designed to be used as a replacement for ESLint's default parser, espree.
eslint-plugin-react-hooks This ESLint plugin enforces the Rules of Hooks.
@typescript-eslint/eslint-plugin An ESLint-specific plugin which, when used in conjunction with @typescript-eslint/parser, allows for TypeScript-specific linting rules to run.
prettier Prettier is an opinionated code formatter.
stylelint A mighty, modern linter that helps you avoid errors and enforce conventions in your styles.
stylelint-config-prettier Turns off all rules that are unnecessary or might conflict with prettier.

Install Dependencies & Add Config Files

yarn add -D typescript @types/jest @types/node @types/react @types/react-dom @types/styled-components eslint-config-airbnb eslint-config-prettier eslint-config-unicorn eslint-plugin-import eslint-plugin-jest eslint-plugin-jsx-a11y eslint-plugin-prettier eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-unicorn @typescript-eslint/parser @typescript-eslint/eslint-plugin prettier stylelint stylelint-config-prettier stylelint-config-recommended stylelint-config-styled-components stylelint-processor-styled-components

(optional) Update dependencies to latest version

yarn upgrade --latest

Create linter config files

touch .eslintrc .prettierrc .stylelintrc


tsconfig.json

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "lib": ["dom", "es6", "es2017", "esnext"],
    "sourceMap": true,
    "outDir": "public/",
    "moduleResolution": "node",
    "declaration": false,
    "composite": false,
    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": false,
    "strictFunctionTypes": true,
    "noImplicitThis": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "newLine": "LF",
    "experimentalDecorators": true,
    "skipLibCheck": true,
    "allowJs": false,
    "jsx": "preserve",
    "rootDir": "src",
    "forceConsistentCasingInFileNames": true,
    "suppressImplicitAnyIndexErrors": true,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true
  },
  "include": [
    "next-env.d.ts",
    "**/*.ts",
    "**/*.tsx"
  ],
  "exclude": ["node_modules", "public"]
}

.eslintrc

{
  "extends": [
    "airbnb-base",
    "plugin:@typescript-eslint/recommended",
    "plugin:react/recommended"
  ],
  "parser": "@typescript-eslint/parser",
  "plugins": ["@typescript-eslint/eslint-plugin"],
  "env": {
    "browser": false,
    "node": true,
    "jest": true
  },
  "settings": {
    "import/resolver": {
      "typescript": {},
      "node": {
        "extensions": [".ts", ".tsx", ".js", ".jsx"]
      }
    }
  },
  "overrides": [
    {
      "files": ["src/**/*.js"],
      "rules": { "@typescript-eslint/no-var-requires": "off" }
    }
  ],
  "rules": {
    "radix": 0,
    "arrow-body-style": 0,
    "no-underscore-dangle": 0,
    "class-methods-use-this": 0,
    "no-confusing-arrow": ["warn"],
    "no-return-assign": ["warn"],
    "@typescript-eslint/camelcase": ["warn"],
    "max-len": ["warn"],
    "no-unused-vars": "off",
    "semi": [2, "always"],
    "@typescript-eslint/indent": ["error", 2],
    "@typescript-eslint/explicit-member-accessibility": "off",
    "@typescript-eslint/explicit-function-return-type": "off",
    "@typescript-eslint/no-unused-vars": ["error", { "args": "none" }],
    "import/extensions": ["off"],
    "no-param-reassign": [2, { "props": false }],
    "@typescript-eslint/no-empty-interface": 0,
    "no-nested-ternary": "warn",
    "react/display-name": "warn",
    "object-curly-newline": [
      "error",
      {
        "ObjectExpression": { "multiline": true, "minProperties": 5 },
        "ObjectPattern": { "multiline": true, "minProperties": 5 },
        "ImportDeclaration": { "multiline": true, "minProperties": 5 },
        "ExportDeclaration": { "multiline": true, "minProperties": 5 }
      }
    ],
    "@typescript-eslint/ban-ts-ignore": "off",
    "comma-dangle": "warn"
  }
}

.prettierrc

{
  "printWidth": 80,
  "tabWidth": 2,
  "useTabs": false,
  "semi": true,
  "singleQuote": true,
  "trailingComma": "es5",
  "bracketSpacing": true,
  "jsxBracketSameLine": false
}

.stylelintrc

{
  "processors": ["stylelint-processor-styled-components"],
  "extends": [
    "stylelint-config-recommended",
    "stylelint-config-styled-components",
    "stylelint-config-prettier"
  ]
}

To-Do

  • add links and descriptions for remaining dependencies

  • add brief explanations for important/most-used linter preferences

About

A custom TypeScript-based create-react-app boilerplate including all the necessary linting files & encourages up-to-date best-practices.


Languages

Language:TypeScript 72.5%Language:HTML 17.8%Language:CSS 9.7%