Skip to content

Commit

Permalink
3.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
SrBrahma committed Dec 3, 2023
1 parent ff63fc6 commit 61fdc93
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 38 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
> Changes to the `js` flavor are also applied to all the other flavors.
> Changes to the `ts` flavor are also applied to `react` and `react-native` flavors.
## 3.7.0

- Add `'@typescript-eslint/array-type': ['warn', { default: 'generic' }]`
- Add `'@typescript-eslint/prefer-string-starts-ends-with': 'warn'`
- Add package `@stylistic/eslint-plugin`
- Add `"padding-line-between-statements"` for multiple situations

## 3.6.0

- Revert previous minor for functions and use `'eslint-plugin-prefer-arrow-functions'` instead as it has autofix.
Expand Down
14 changes: 14 additions & 0 deletions js.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = {
'no-relative-import-paths',
'jsdoc',
'prefer-arrow-functions',
'@stylistic',
],
extends: ['eslint:recommended', 'plugin:jsdoc/recommended', './removeFormatter/js.js'],
rules: {
Expand Down Expand Up @@ -160,5 +161,18 @@ module.exports = {
'jsdoc/require-jsdoc': 'off',
'jsdoc/require-param': 'off',
'jsdoc/require-returns': 'off',

'@stylistic/padding-line-between-statements': [
'warn',
// Line before return
{ blankLine: 'always', prev: '*', next: 'return' },
// Line after vars block
{ blankLine: 'always', prev: ['const', 'let', 'var'], next: '*' },
{ blankLine: 'any', prev: ['const', 'let', 'var'], next: ['const', 'let', 'var'] },
// Line before function
{ blankLine: 'always', prev: '*', next: 'function' },
// Line before type/interface (TS)
{ blankLine: 'always', prev: '*', next: ['interface', 'type'] },
],
},
};
107 changes: 107 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-config-gev",
"version": "3.6.0",
"version": "3.7.0",
"description": "Common ESLint configs for my JS/TS and React/RN projects",
"main": "index.js",
"bin": "bin.js",
Expand Down Expand Up @@ -41,19 +41,20 @@
"homepage": "https://github.com/SrBrahma/eslint-config#readme",
"dependencies": {
"@rushstack/eslint-patch": "1.6.0",
"@stylistic/eslint-plugin": "^1.4.1",
"@typescript-eslint/eslint-plugin": "6.13.1",
"@typescript-eslint/parser": "6.13.1",
"commander": "9.4.1",
"eslint": "8.55.0",
"eslint-plugin-import": "2.29.0",
"eslint-plugin-jsdoc": "^46.9.0",
"eslint-plugin-no-autofix": "1.2.3",
"eslint-plugin-no-relative-import-paths": "^1.5.3",
"eslint-plugin-prefer-arrow-functions": "^3.2.4",
"eslint-plugin-react": "7.33.2",
"eslint-plugin-react-hooks": "4.6.0",
"eslint-plugin-react-native": "4.1.0",
"eslint-plugin-simple-import-sort": "10.0.0",
"eslint-plugin-jsdoc": "^46.9.0",
"eslint-plugin-unused-imports": "3.0.0"
},
"devDependencies": {
Expand Down
15 changes: 7 additions & 8 deletions scripts/makeTsExtensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const filePath = path.join(rootPath, 'ts-extensions.js');
*
* This is a cool automatic hack to do this convertion.
*/
function makeTsExtensions() {
const makeTsExtensions = () => {
/** Record<string, any> */
const config = JSON.parse(
execaCommandSync('npx eslint --print-config dont-care.js', {
Expand Down Expand Up @@ -43,9 +43,9 @@ function makeTsExtensions() {
.filter(([, [v]]) => v !== 0 && v !== 'off');

writeFile(tsRulesThatExtends);
}
};

function writeFile(rules) {
const writeFile = (rules) => {
const data = `/**
* File smartly and automatically generated by my scripts/makeTsExtensions.js
*
Expand All @@ -55,7 +55,7 @@ function writeFile(rules) {
module.exports = {
rules: {
${rules.map((r) => getReplaceString(...r)).join('\n\n')}
${rules.map((r) => ' ' + getReplaceString(...r)).join('\n\n')}
}
}
`;
Expand All @@ -64,10 +64,9 @@ ${rules.map((r) => getReplaceString(...r)).join('\n\n')}

// ESLint it!
execa('npx', ['eslint', filePath, '--fix'], { cwd: rootPath });
}
};

function getReplaceString(rule, value) {
return `['${rule}']: 'off',\n` + `['@typescript-eslint/${rule}']: ${JSON.stringify(value)},`;
}
const getReplaceString = (rule, value) =>
`['${rule}']: 'off',\n` + `['@typescript-eslint/${rule}']: ${JSON.stringify(value)},`;

makeTsExtensions();
40 changes: 22 additions & 18 deletions ts-extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,32 @@

module.exports = {
rules: {
['default-param-last']: 'off',
['@typescript-eslint/default-param-last']: ["error"],
['default-param-last']: 'off',
['@typescript-eslint/default-param-last']: ['error'],

['lines-between-class-members']: 'off',
['@typescript-eslint/lines-between-class-members']: ["warn","always",{"exceptAfterSingleLine":true}],
['lines-between-class-members']: 'off',
['@typescript-eslint/lines-between-class-members']: [
'warn',
'always',
{ exceptAfterSingleLine: true },
],

['no-dupe-class-members']: 'off',
['@typescript-eslint/no-dupe-class-members']: ["error"],
['no-dupe-class-members']: 'off',
['@typescript-eslint/no-dupe-class-members']: ['error'],

['no-loss-of-precision']: 'off',
['@typescript-eslint/no-loss-of-precision']: ["error"],
['no-loss-of-precision']: 'off',
['@typescript-eslint/no-loss-of-precision']: ['error'],

['no-redeclare']: 'off',
['@typescript-eslint/no-redeclare']: ["error"],
['no-redeclare']: 'off',
['@typescript-eslint/no-redeclare']: ['error'],

['no-throw-literal']: 'off',
['@typescript-eslint/no-throw-literal']: ["warn"],
['no-throw-literal']: 'off',
['@typescript-eslint/no-throw-literal']: ['warn'],

['no-unused-vars']: 'off',
['@typescript-eslint/no-unused-vars']: ["warn",{"ignoreRestSiblings":true}],
['no-unused-vars']: 'off',
['@typescript-eslint/no-unused-vars']: ['warn', { ignoreRestSiblings: true }],

['require-await']: 'off',
['@typescript-eslint/require-await']: ["warn"],
}
}
['require-await']: 'off',
['@typescript-eslint/require-await']: ['warn'],
},
};
42 changes: 32 additions & 10 deletions ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ module.exports = {
/** Disable it to allow empty catch blocks. */
'@typescript-eslint/no-empty-function': 'off',

/** This is kinda useless. It's more of a pain, actually:
/**
* This is kinda useless. It's more of a pain, actually:
* If you are writting a function like f({}: Props) to later fill the object with the desired props,
* it will mark it as an error.
* https://eslint.org/docs/rules/no-empty-pattern */
* https://eslint.org/docs/rules/no-empty-pattern
*/
'no-empty-pattern': 'off',

/** https://typescript-eslint.io/rules/no-unnecessary-condition/ */
Expand All @@ -59,8 +61,10 @@ module.exports = {
},
],

/** =========== Unsafe ===========
* === Be responsible and careful! ==== */
/**
* =========== Unsafe ===========
* === Be responsible and careful! ====
*/

// Allows using `a!.b`. Not safe, but sometimes we really know it is valid.

Expand All @@ -70,26 +74,32 @@ module.exports = {
/** [2022-02-03] It's bugging often, so I disabled it. */
'@typescript-eslint/restrict-plus-operands': 'off',

/** Improves tree-shaking and improves TS optimization.
* https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/consistent-type-imports.md */
/**
* Improves tree-shaking and improves TS optimization.
* https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/consistent-type-imports.md
*/
'@typescript-eslint/consistent-type-imports': [
'warn',
{
disallowTypeAnnotations: false, // Allows import('foo').Bar. Useful in global.d.ts.
},
],

/** Remove unnecessary boolean literal conditionals`.
* https://typescript-eslint.io/rules/no-unnecessary-boolean-literal-compare */
/**
* Remove unnecessary boolean literal conditionals`.
* https://typescript-eslint.io/rules/no-unnecessary-boolean-literal-compare
*/
'@typescript-eslint/no-unnecessary-boolean-literal-compare': [
'warn',
{
allowComparingNullableBooleansToTrue: false,
},
],

/** TS handles this, it raised false-positives sometimes.
* https://github.com/Chatie/eslint-config/issues/45#issuecomment-1003990077 */
/**
* TS handles this, it raised false-positives sometimes.
* https://github.com/Chatie/eslint-config/issues/45#issuecomment-1003990077
*/
'no-undef': 'off',

/** -=-=-=- Disallow dangerous stuff, converts recommended warn to error -=-=-=- */
Expand All @@ -100,6 +110,18 @@ module.exports = {
'@typescript-eslint/no-unsafe-argument': 'error',
'@typescript-eslint/no-unsafe-call': 'error',
'@typescript-eslint/no-non-null-assertion': 'error',

/**
* Prefer Array<string> instead of string[]. Faster to read and to change.
*
* https://typescript-eslint.io/rules/array-type/
*/
'@typescript-eslint/array-type': ['warn', { default: 'generic' }],

/**
* https://typescript-eslint.io/rules/prefer-string-starts-ends-with/
*/
'@typescript-eslint/prefer-string-starts-ends-with': 'warn',
},
};

Expand Down

0 comments on commit 61fdc93

Please sign in to comment.