Skip to content

Commit

Permalink
DEV-12121: add typescript import rules (#41)
Browse files Browse the repository at this point in the history
* DEV-12121: add typescript import rules

* Feat (DEV-12121-typescript-import-rules): new version
  • Loading branch information
PascalLuginbuehl authored Oct 17, 2023
1 parent f58fb9e commit 4a590dd
Show file tree
Hide file tree
Showing 6 changed files with 2,184 additions and 221 deletions.
3 changes: 3 additions & 0 deletions flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ module.exports = {
'*.jsx',
],
rules: {
'no-undef': 'off',
'import/no-named-as-default': 'off',

'unicode-bom': ['error', 'never'],
'flowtype/boolean-style': [
2,
Expand Down
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@competec/eslint-config-competec",
"version": "2.7.0",
"version": "2.7.1",
"description": "Competec ESLint Rules",
"keywords": [
"eslint",
Expand All @@ -19,7 +19,7 @@
"author": "Raphael Hättich / Competec",
"main": "index.js",
"peerDependencies": {
"eslint": "8.x"
"eslint": ">=7"
},
"license": "MIT",
"devDependencies": {
Expand All @@ -37,15 +37,16 @@
"@babel/eslint-parser": "^7.19.1",
"@babel/plugin-transform-runtime": "^7.19.6",
"@babel/preset-env": "^7.20.2",
"@typescript-eslint/eslint-plugin": "^5.42.1",
"@typescript-eslint/parser": "^5.42.1",
"eslint-config-react-app": "^5.2.1",
"@typescript-eslint/eslint-plugin": "^6.7.5",
"@typescript-eslint/parser": "^6.7.5",
"eslint-config-react-app": "^7.0.1",
"eslint-import-resolver-typescript": "^3.5.2",
"eslint-plugin-flowtype": "^4.7.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-jsx-a11y": "^6.6.1",
"eslint-plugin-react": "^7.31.10",
"eslint-plugin-react-hooks": "^2.5.1"
"eslint-plugin-react-hooks": "^2.5.1",
"typescript": "^4.7.4"
},
"scripts": {
"reset": "rm -rf ./node_modules && yarn",
Expand Down
5 changes: 1 addition & 4 deletions react.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@


module.exports = {
plugins: [
'jsx-a11y',
],
extends: [
'plugin:jsx-a11y/recommended',
'react-app',
'plugin:jsx-a11y/recommended',
'./src/base.js',
],
rules: {
Expand Down
21 changes: 5 additions & 16 deletions src/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,6 @@ module.exports = {
'vars-on-top': 'off',
'wrap-iife': ['error', 'outside'],
yoda: ['error', 'never'],
'import/order': [
'error',
{
'groups': [
'builtin',
'external',
'internal',
'parent',
'sibling',
'index',
'object',
'type',
],
}
],

// Strict Mode
strict: ['error', 'safe'],
Expand Down Expand Up @@ -219,7 +204,6 @@ module.exports = {
'require-jsdoc': 'off',
semi: ['error', 'always'],
'semi-spacing': 'error',
'sort-imports': 'off',
'sort-vars': 'off',
'space-before-blocks': ['error', 'always'],
'space-before-function-paren': ['error', {anonymous: 'never', named: 'never'}],
Expand Down Expand Up @@ -251,5 +235,10 @@ module.exports = {
'prefer-spread': 1,
'prefer-template': 1,
'require-yield': 2,

// Disabled due to incorrect errors https://typescript-eslint.io/rules/no-use-before-define/#how-to-use
'no-use-before-define': 'off',

'import/no-anonymous-default-export': 'off',
},
};
79 changes: 74 additions & 5 deletions typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,34 @@
//------------------------------------------------------------------------------

module.exports = {
plugins: [
'@typescript-eslint',
],
parserOptions: {
warnOnUnsupportedTypeScriptVersion: false,
},
settings: {
typescript: true,
node: true,
'import/resolver': {
typescript: true,
node: true,
},
},
parser: '@typescript-eslint/parser',
overrides: [
{
parser: '@typescript-eslint/parser',
extends: [
'plugin:@typescript-eslint/recommended',
// Error: Not uniquely imported, also gets imported by eslint-config-react-app
// 'plugin:@typescript-eslint/recommended',
'plugin:import/recommended',
'plugin:import/typescript',
],
files: [
'*.ts',
'*.tsx',
],
rules: {
'import/no-named-as-default': 'off',
'import/no-named-as-default-member': 'off',

'no-inner-declarations': 'off',
semi: 'off',
'no-extra-parens': 'off',
Expand All @@ -36,7 +43,69 @@ module.exports = {
],
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/member-delimiter-style': 'off',

'@typescript-eslint/ban-ts-ignore': 'off',
'@typescript-eslint/ban-ts-comment': 'off',

'flowtype/no-types-missing-file-annotation': 'off',

// Disabled due to incorrect errors https://typescript-eslint.io/rules/no-use-before-define/#how-to-use
'no-use-before-define': 'off',
'@typescript-eslint/no-use-before-define': 'error',

'@typescript-eslint/no-import-type-side-effects': 'error',

'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': 'off',

// needs to be removed in the future: https://stackoverflow.com/questions/64170868/why-eslint-consider-jsx-or-some-react-types-undefined-since-upgrade-typescript
'no-undef': 'off',

// https://typescript-eslint.io/rules/no-shadow/#how-to-use
'no-shadow': 'off',
'@typescript-eslint/no-shadow': 'error',

'import/order': [
'error',
{
alphabetize: {
order: 'asc',
caseInsensitive: false,
},
pathGroups: [
{
pattern: '{react,react-dom}',
group: 'builtin',
position: 'before',
},
{
pattern: '{jest-axe,enzyme,react-dom/test-utils}',
group: 'builtin',
position: 'after',
},
{
pattern: '*storybook*',
group: 'builtin',
position: 'after',
},
{
pattern: '{@competec/**,b2c-components/**,b2c-resources/**}',
group: 'external',
position: 'after',
},
],
pathGroupsExcludedImportTypes: [],
groups: [
'builtin',
'external',
'parent',
'sibling',
'index',
'type',
],
},
],
'import/newline-after-import': 'error',
},
},
],
Expand Down
Loading

0 comments on commit 4a590dd

Please sign in to comment.