Skip to content

Commit

Permalink
Add support for JS files on TS projects (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fryuni authored Feb 8, 2022
1 parent 8c6d5e7 commit fd8f779
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 98 deletions.
8 changes: 3 additions & 5 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
{
"parser": "@typescript-eslint/parser",
"plugins": [
"self",
"eslint-plugin"
],
"extends": [
"plugin:self/typescript",
"plugin:eslint-plugin/recommended"
"plugin:eslint-plugin/recommended",
"plugin:self/typescript"
],
"parserOptions": {
"extends": "./tsconfig.json",
"project": ["./tsconfig.json"]
"project": ["**/tsconfig.json"]
}
}
24 changes: 13 additions & 11 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,19 @@ To enable this preset, add the following to your `.eslintrc` file:

Enforces Croct's standard TypeScript best practices.

To enable this preset, add the following to your `.eslintrc` file:

```json
{
"plugins": [
"@croct"
],
"extends": [
"plugin:@croct/typescript"
]
}
To enable this preset, add the following to your `.eslintrc.js` file:

```js
// This is a workaround for https://github.com/eslint/eslint/issues/3458
require('@rushstack/eslint-patch/modern-module-resolution');

module.exports = {
plugins: ['@croct'],
extends: ['plugin:@croct/typescript'],
parserOptions: {
project: ['**/tsconfig.json'],
},
};
```

This preset extends the JavaScript preset – no need to include it as well.
Expand Down
147 changes: 65 additions & 82 deletions src/configs/typescript.ts
Original file line number Diff line number Diff line change
@@ -1,93 +1,76 @@
export const typescript = {
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:@croct/javascript',
],
extends: ['plugin:@croct/javascript'],
plugins: [
'@typescript-eslint',
'@croct',
],
rules: {
'@typescript-eslint/array-type': [
'error',
{
default: 'array-simple',
},
],
'@typescript-eslint/prefer-as-const': 'error',
'@typescript-eslint/adjacent-overload-signatures': 'error',
'@typescript-eslint/type-annotation-spacing': 'error',
'@typescript-eslint/semi': ['error', 'always'],
'@typescript-eslint/strict-boolean-expressions': [
'error',
{
allowString: false,
allowNumber: false,
allowNullableObject: false,
},
],
'@typescript-eslint/prefer-regexp-exec': 'error',
'@typescript-eslint/prefer-optional-chain': 'error',

'no-shadow': 'off',
'@typescript-eslint/no-shadow': [
'error',
{
ignoreTypeValueShadow: true,
ignoreFunctionTypeParameterNameValueShadow: true,
},
],
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/explicit-member-accessibility': [
'error',
],
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/explicit-function-return-type': [
'error',
],
'@typescript-eslint/no-explicit-any': 'off',
'no-use-before-define': 'off',
'@typescript-eslint/no-use-before-define': 'error',
'no-unused-expressions': 'off',
'@typescript-eslint/no-unused-expressions': 'error',
indent: [
'error',
4,
{
SwitchCase: 1,
},
],
'@typescript-eslint/no-unused-vars': 'error',
'no-unused-vars': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'object-curly-spacing': 'off',
'@typescript-eslint/object-curly-spacing': 'error',
'@typescript-eslint/member-delimiter-style': [
'error',
{
multiline: {
delimiter: 'comma',
requireLast: true,
},
singleline: {
delimiter: 'comma',
requireLast: false,
},
overrides: {
interface: {
singleline: {
delimiter: 'semi',
},
multiline: {
delimiter: 'semi',
overrides: [
{
files: ['**/*.ts', '**/*.tsx'],
extends: ['plugin:@typescript-eslint/recommended'],
parser: '@typescript-eslint/parser',
rules: {
'@typescript-eslint/array-type': ['error', {
default: 'array-simple',
}],
'@typescript-eslint/prefer-as-const': 'error',
'@typescript-eslint/adjacent-overload-signatures': 'error',
'@typescript-eslint/type-annotation-spacing': 'error',
'@typescript-eslint/semi': ['error', 'always'],
'@typescript-eslint/strict-boolean-expressions': ['error', {
allowString: false,
allowNumber: false,
allowNullableObject: false,
}],
'@typescript-eslint/prefer-regexp-exec': 'error',
'@typescript-eslint/prefer-optional-chain': 'error',
'no-shadow': 'off',
'@typescript-eslint/no-shadow': ['error', {
ignoreTypeValueShadow: true,
ignoreFunctionTypeParameterNameValueShadow: true,
}],
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/explicit-member-accessibility': [
'error',
],
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/explicit-function-return-type': ['error'],
'@typescript-eslint/no-explicit-any': 'off',
'no-use-before-define': 'off',
'@typescript-eslint/no-use-before-define': 'error',
'no-unused-expressions': 'off',
'@typescript-eslint/no-unused-expressions': 'error',
indent: ['error', 4, {
SwitchCase: 1,
}],
'@typescript-eslint/no-unused-vars': 'error',
'no-unused-vars': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'object-curly-spacing': 'off',
'@typescript-eslint/object-curly-spacing': 'error',
'@typescript-eslint/member-delimiter-style': ['error', {
multiline: {
delimiter: 'comma',
requireLast: true,
},
singleline: {
delimiter: 'comma',
requireLast: false,
},
overrides: {
interface: {
singleline: {
delimiter: 'semi',
},
multiline: {
delimiter: 'semi',
},
},
},
},
}],
'no-undef': 'off',
},
],
'no-undef': 'off',
},
overrides: [
},
{
files: [
'src/**/*.test.ts',
Expand Down

0 comments on commit fd8f779

Please sign in to comment.