Skip to content

Commit

Permalink
chore(workspace): reducing typescript config complexity (#647)
Browse files Browse the repository at this point in the history
#### What this PR does / why we need it:

As per title.
  • Loading branch information
fuxingloh authored Oct 20, 2023
1 parent a327722 commit 1d70c05
Show file tree
Hide file tree
Showing 25 changed files with 330 additions and 436 deletions.
29 changes: 0 additions & 29 deletions .eslintrc

This file was deleted.

113 changes: 113 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
module.exports = {
plugins: ['simple-import-sort', 'check-file', 'unused-imports', 'no-only-tests'],
extends: ['airbnb-base', 'airbnb-typescript/base', 'prettier'],
ignorePatterns: ['dist', 'node_modules'],
rules: {
'class-methods-use-this': 'off',
'max-classes-per-file': 'off',
'no-use-before-define': 'off',
'no-console': 'error',

// https://github.com/airbnb/javascript/issues/1271
'no-restricted-syntax': 'off',

'no-await-in-loop': 'off',

// import
'import/no-extraneous-dependencies': 'off',
'import/prefer-default-export': 'off',
'import/no-default-export': 'error',

// simple-import-sort
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error',

/**
* Enforce PascalCase for filenames.
*/
'check-file/filename-naming-convention': [
'error',
{
'src/**/*.{js,jsx,tsx,ts}': 'PASCAL_CASE',
},
{
ignoreMiddleExtensions: true,
},
],

'@typescript-eslint/no-throw-literal': 'warn',

'@typescript-eslint/no-floating-promises': 'error',
'no-void': [
'error',
{
allowAsStatement: true,
},
],

// @typescript-eslint
'@typescript-eslint/no-use-before-define': 'off',

/**
* Separates out the `no-unused-vars` rule depending on it being an import statement in the AST and providing
* an auto-fix rule to remove the nodes if they are imports.
* With this, we can now target test files with `'unused-imports/no-unused-vars': 'off'` for testing DX.
*/
'@typescript-eslint/no-unused-vars': 'off',
'unused-imports/no-unused-imports': 'error',
'unused-imports/no-unused-vars': 'error',

/**
* Do not use ambiguous identifiers like `id`, use context identifiers like `userId` or `postId` instead.
* Please do not ignore this rule completely, for scenarios where you need to use `id` as a variable name,
* use `// eslint-disable-next-line no-restricted-properties` to disable this rule for that line.
*/
'no-restricted-properties': [
'error',
{
property: 'id',
message:
'Do not use ambiguous identifiers like `id`, use context identifiers like `userId` or `postId` instead.',
},
],

/**
* disallow .only to be used in tests
*/
'no-only-tests/no-only-tests': 'error',
},
env: {
node: true,
jest: true,
},
overrides: [
{
files: ['**/*.unit.ts', '**/*.i9n.ts', '**/*.e2e.ts'],
rules: {
/**
* To cater for complex test scenarios, where we need to scope blocks. This allows variables to be reused,
* so we don't have to create `const getObject` and `const updatedObject` for each scenario.
* We can just use `const object`.
*/
'no-lone-blocks': 'off',

/**
* Separates out the `no-unused-vars` rule depending on it being an import statement in the AST and providing
* an auto-fix rule to remove the nodes if they are imports.
* With this, we can now target test files with `'unused-imports/no-unused-vars': 'off'` for testing DX.
*/
'unused-imports/no-unused-imports': 'error',
'unused-imports/no-unused-vars': 'off',
},
},
{
/**
* Enforce PascalCase for filenames, ignoring common files like `index.ts`, `cli.ts`, `main.ts`.
*/
files: ['**/{index,cli}.ts'],
rules: {
'check-file/filename-naming-convention': ['off'],
},
},
],
};
6 changes: 0 additions & 6 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
# Hosting Dev Tools
public-hoist-pattern[]=husky
public-hoist-pattern[]=lint-staged
public-hoist-pattern[]=typescript
public-hoist-pattern[]=turbo
public-hoist-pattern[]=*jest*
public-hoist-pattern[]=*eslint*
public-hoist-pattern[]=*prettier*
public-hoist-pattern[]=@types/*
24 changes: 20 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,27 @@
"lint-staged": {
"*": "prettier --write --ignore-unknown"
},
"prettier": "@stickyjs/prettier",
"devDependencies": {
"@stickyjs/eslint-config": "1.3.4",
"@stickyjs/prettier": "1.3.4",
"turbo": "^1.10.16"
"@typescript-eslint/eslint-plugin": "^6.7.0",
"@typescript-eslint/parser": "^6.7.0",
"@workspace/jest-preset": "workspace:*",
"@workspace/tsconfig": "workspace:*",
"eslint": "^8.49.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^17.1.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-check-file": "^2.6.2",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-no-only-tests": "^3.1.0",
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-unused-imports": "^3.0.0",
"husky": "^8.0.3",
"lint-staged": "^14.0.1",
"prettier": "^3.0.3",
"prettier-plugin-packagejson": "^2.4.5",
"prettier-plugin-tailwindcss": "^0.4.1",
"turbo": "^1.10.16",
"typescript": "5.2.2"
},
"packageManager": "[email protected]",
"engines": {
Expand Down
5 changes: 1 addition & 4 deletions packages/contented-example/jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
"eslintConfig": {
"parserOptions": {
"project": "./tsconfig.json"
},
"extends": [
"@stickyjs"
]
}
},
"jest": {
"preset": "@workspace/jest-preset",
Expand Down
10 changes: 3 additions & 7 deletions packages/contented-pipeline-jest-md/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"dist"
],
"scripts": {
"build": "tsc -b ./tsconfig.build.json",
"build": "tsc --project tsconfig.build.json",
"clean": "rm -rf dist",
"lint": "eslint src",
"test": "jest"
Expand All @@ -30,10 +30,7 @@
"eslintConfig": {
"parserOptions": {
"project": "./tsconfig.json"
},
"extends": [
"@stickyjs"
]
}
},
"jest": {
"preset": "@workspace/jest-preset"
Expand All @@ -47,7 +44,6 @@
"vfile": "^5.3.7"
},
"devDependencies": {
"@workspace/jest-preset": "workspace:*",
"typescript": "4.9.5"
"@workspace/jest-preset": "workspace:*"
}
}
6 changes: 5 additions & 1 deletion packages/contented-pipeline-jest-md/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"extends": "./tsconfig.json",
"extends": "@workspace/tsconfig",
"compilerOptions": {
"outDir": "dist"
},
"include": ["src"],
"exclude": ["**/*.unit.ts"]
}
7 changes: 1 addition & 6 deletions packages/contented-pipeline-jest-md/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist"
},
"include": ["src"]
"extends": "@workspace/tsconfig"
}
8 changes: 2 additions & 6 deletions packages/contented-pipeline-md/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"dist"
],
"scripts": {
"build": "tsc -b ./tsconfig.build.json",
"build": "tsc --project tsconfig.build.json",
"clean": "rm -rf dist",
"lint": "eslint src",
"test": "jest"
Expand All @@ -31,9 +31,6 @@
"parserOptions": {
"project": "./tsconfig.json"
},
"extends": [
"@stickyjs"
],
"rules": {
"no-param-reassign": "off"
}
Expand Down Expand Up @@ -75,7 +72,6 @@
"@types/hast": "^2.3.6",
"@types/js-yaml": "^4.0.6",
"@types/lodash": "^4.14.199",
"@workspace/jest-preset": "workspace:*",
"typescript": "4.9.5"
"@workspace/jest-preset": "workspace:*"
}
}
6 changes: 5 additions & 1 deletion packages/contented-pipeline-md/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"extends": "./tsconfig.json",
"extends": "@workspace/tsconfig",
"compilerOptions": {
"outDir": "dist"
},
"include": ["src"],
"exclude": ["**/*.unit.ts"]
}
7 changes: 1 addition & 6 deletions packages/contented-pipeline-md/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist"
},
"include": ["src"]
"extends": "@workspace/tsconfig"
}
10 changes: 3 additions & 7 deletions packages/contented-pipeline/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"dist"
],
"scripts": {
"build": "tsc -b ./tsconfig.build.json",
"build": "tsc --project tsconfig.build.json",
"clean": "rm -rf dist",
"lint": "eslint src",
"lint": "eslint .",
"test": "jest"
},
"lint-staged": {
Expand All @@ -31,9 +31,6 @@
"parserOptions": {
"project": "./tsconfig.json"
},
"extends": [
"@stickyjs"
],
"rules": {
"no-param-reassign": "off"
}
Expand All @@ -46,7 +43,6 @@
},
"devDependencies": {
"@types/unist": "^2.0.8",
"@workspace/jest-preset": "workspace:*",
"typescript": "4.9.5"
"@workspace/jest-preset": "workspace:*"
}
}
6 changes: 5 additions & 1 deletion packages/contented-pipeline/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"extends": "./tsconfig.json",
"extends": "@workspace/tsconfig",
"compilerOptions": {
"outDir": "dist"
},
"include": ["src"],
"exclude": ["**/*.unit.ts"]
}
7 changes: 1 addition & 6 deletions packages/contented-pipeline/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist"
},
"include": ["src"]
"extends": "@workspace/tsconfig"
}
8 changes: 2 additions & 6 deletions packages/contented-processor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"dist"
],
"scripts": {
"build": "tsc -b ./tsconfig.build.json",
"build": "tsc --project tsconfig.build.json",
"clean": "rm -rf dist",
"lint": "eslint src",
"test": "jest"
Expand All @@ -31,9 +31,6 @@
"parserOptions": {
"project": "./tsconfig.json"
},
"extends": [
"@stickyjs"
],
"rules": {
"no-param-reassign": "off"
}
Expand All @@ -50,7 +47,6 @@
"devDependencies": {
"@types/minimatch": "^5.1.2",
"@types/node": "^18.16.16",
"@workspace/jest-preset": "workspace:*",
"typescript": "4.9.5"
"@workspace/jest-preset": "workspace:*"
}
}
6 changes: 5 additions & 1 deletion packages/contented-processor/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"extends": "./tsconfig.json",
"extends": "@workspace/tsconfig",
"compilerOptions": {
"outDir": "dist"
},
"include": ["src"],
"exclude": ["**/*.unit.ts"]
}
7 changes: 1 addition & 6 deletions packages/contented-processor/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist"
},
"include": ["src"]
"extends": "@workspace/tsconfig"
}
Loading

0 comments on commit 1d70c05

Please sign in to comment.