Skip to content

Commit

Permalink
fix: subject fixed failure to propgate extension rules present in sta…
Browse files Browse the repository at this point in the history
…ndard
  • Loading branch information
6XGate committed May 29, 2021
1 parent 449030e commit 75a9d51
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 15 deletions.
8 changes: 4 additions & 4 deletions package.json
Expand Up @@ -55,24 +55,24 @@
"TypeScript"
],
"dependencies": {
"@typescript-eslint/parser": "^4.0.0",
"@typescript-eslint/parser": "^4.15.0",
"eslint-config-standard": "^16.0.0"
},
"peerDependencies": {
"@typescript-eslint/eslint-plugin": ">=4.15.0",
"eslint": ">=7.12.1",
"eslint-plugin-import": ">=2.22.1",
"eslint-plugin-node": ">=11.1.0",
"eslint-plugin-promise": ">=4.2.1",
"typescript": ">=3.9",
"@typescript-eslint/eslint-plugin": ">=4.0.1"
"typescript": ">=3.9"
},
"devDependencies": {
"@commitlint/cli": "12.1.4",
"@commitlint/config-conventional": "12.1.4",
"@commitlint/travis-cli": "12.1.4",
"@types/eslint": "7.2.12",
"@types/node": "14.17.1",
"@typescript-eslint/eslint-plugin": "4.0.1",
"@typescript-eslint/eslint-plugin": "4.15.0",
"ava": "3.15.0",
"editorconfig-checker": "3.3.0",
"eslint": "7.27.0",
Expand Down
28 changes: 27 additions & 1 deletion src/index.test.ts
Expand Up @@ -35,6 +35,7 @@ test('export', (t): void => {
rules: {
'brace-style': 'off',
camelcase: 'off',
'comma-dangle': 'off',
'comma-spacing': 'off',
'default-param-last': 'off',
'dot-notation': 'off',
Expand All @@ -44,6 +45,9 @@ test('export', (t): void => {
'lines-between-class-members': 'off',
'no-array-constructor': 'off',
'no-dupe-class-members': 'off',
'no-extra-parens': 'off',
'no-implied-eval': 'off',
'no-loss-of-precision': 'off',
'no-redeclare': 'off',
'no-throw-literal': 'off',
'no-undef': 'off',
Expand All @@ -52,12 +56,24 @@ test('export', (t): void => {
'no-unused-expressions': 'off',
'no-useless-constructor': 'off',
'no-void': ['error', { allowAsStatement: true }],
'object-curly-spacing': 'off',
quotes: 'off',
semi: 'off',
'space-before-function-paren': 'off',
'space-infix-ops': 'off',
'@typescript-eslint/adjacent-overload-signatures': 'error',
'@typescript-eslint/array-type': ['error', { default: 'array-simple' }],
'@typescript-eslint/brace-style': ['error', '1tbs', { allowSingleLine: true }],
'@typescript-eslint/comma-dangle': [
'error',
{
arrays: 'never',
exports: 'never',
functions: 'never',
imports: 'never',
objects: 'never'
}
],
'@typescript-eslint/comma-spacing': ['error', { before: false, after: true }],
'@typescript-eslint/consistent-type-assertions': [
'error',
Expand Down Expand Up @@ -114,11 +130,16 @@ test('export', (t): void => {
'@typescript-eslint/no-dynamic-delete': 'error',
'@typescript-eslint/no-empty-interface': ['error', { allowSingleExtends: true }],
'@typescript-eslint/no-extra-non-null-assertion': 'error',
'@typescript-eslint/no-extra-parens': [
'error',
'functions'
],
'@typescript-eslint/no-extraneous-class': ['error', { allowWithDecorator: true }],
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/no-for-in-array': 'error',
'@typescript-eslint/no-implied-eval': 'error',
'@typescript-eslint/no-invalid-void-type': 'error',
'@typescript-eslint/no-loss-of-precision': 'error',
'@typescript-eslint/no-misused-new': 'error',
'@typescript-eslint/no-misused-promises': 'error',
'@typescript-eslint/no-namespace': 'error',
Expand All @@ -134,6 +155,10 @@ test('export', (t): void => {
'@typescript-eslint/no-unused-expressions': ['error', { allowShortCircuit: true, allowTaggedTemplates: true, allowTernary: true }],
'@typescript-eslint/no-useless-constructor': 'error',
'@typescript-eslint/no-var-requires': 'error',
'@typescript-eslint/object-curly-spacing': [
'error',
'always'
],
'@typescript-eslint/prefer-function-type': 'error',
'@typescript-eslint/prefer-includes': 'error',
'@typescript-eslint/prefer-nullish-coalescing': ['error', { ignoreConditionalTests: false, ignoreMixedLogicalExpressions: false }],
Expand All @@ -149,6 +174,7 @@ test('export', (t): void => {
'@typescript-eslint/return-await': ['error', 'always'],
'@typescript-eslint/semi': ['error', 'never'],
'@typescript-eslint/space-before-function-paren': ['error', 'always'],
'@typescript-eslint/space-infix-ops': 'error',
'@typescript-eslint/strict-boolean-expressions': ['error', {
allowString: false,
allowNumber: false,
Expand Down Expand Up @@ -192,7 +218,7 @@ test('Own peerDependencies include those of eslint-config-standard', async (t) =
const name = _name as keyof typeof standardPkg.peerDependencies
const ourDep = ourPeerDeps[name]
const ourRange = ourDep.split('>=')[1]
const standardRange = standardDep.split('^')[1]
const standardRange = standardDep.split('^')[1].split('||')[0].trim()
t.is(ourRange, standardRange)
})
})
Expand Down
44 changes: 34 additions & 10 deletions src/index.ts
Expand Up @@ -2,36 +2,61 @@ import configStandard from './eslint-config-standard'
import { Linter } from 'eslint'

const equivalents = [
'brace-style',
'comma-dangle',
'comma-spacing',
'default-param-last',
'dot-notation',
'brace-style',
'func-call-spacing',
'indent',
'init-declarations',
'keyword-spacing',
'lines-between-class-members',
'no-array-constructor',
'no-dupe-class-members',
'no-duplicate-imports',
'no-empty-function',
'no-extra-parens',
'no-extra-semi',
'no-implied-eval',
'no-invalid-this',
'no-loop-func',
'no-loss-of-precision',
'no-magic-numbers',
'no-redeclare',
'no-shadow',
'no-throw-literal',
'no-unused-vars',
'no-unused-expressions',
'no-unused-vars',
'no-use-before-define',
'no-useless-constructor',
'object-curly-spacing',
'quotes',
'require-await',
'semi',
'space-before-function-paren'
'space-before-function-paren',
'space-infix-ops'
] as const

const ruleFromStandard = (name: string): Linter.RuleEntry => {
if (configStandard.rules === undefined) throw new Error()
const rule = configStandard.rules[name]
if (rule === undefined) throw new Error()
const rawRuleFromStandard = (name: string): undefined|Linter.RuleEntry => {
if (configStandard.rules === undefined) return undefined
return configStandard.rules[name]
}

const ruleFromStandard = (name: string): undefined|Linter.RuleEntry => {
const rule = rawRuleFromStandard(name)
if (rule === undefined) return undefined
if (typeof rule !== 'object') return rule
return JSON.parse(JSON.stringify(rule))
}

const disableEquivalentsRule = (name: string): undefined|'off' => {
return rawRuleFromStandard(name) !== undefined ? 'off' : undefined
}

function fromEntries<T> (iterable: Array<[string, T]>): { [key: string]: T } {
return [...iterable].reduce<{ [key: string]: T }>((obj, [key, val]) => {
obj[key] = val
if (val !== undefined) obj[key] = val
return obj
}, {})
}
Expand All @@ -48,7 +73,7 @@ const config: Linter.Config = {
'no-undef': 'off',

// Rules replaced by @typescript-eslint versions:
...fromEntries(equivalents.map((name) => [name, 'off'])),
...fromEntries(equivalents.map((name) => [name, disableEquivalentsRule(name)])),
camelcase: 'off',
'default-param-last': 'off',
'no-use-before-define': 'off',
Expand Down Expand Up @@ -102,7 +127,6 @@ const config: Linter.Config = {
'@typescript-eslint/no-extraneous-class': ['error', { allowWithDecorator: true }],
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/no-for-in-array': 'error',
'@typescript-eslint/no-implied-eval': 'error',
'@typescript-eslint/no-invalid-void-type': 'error',
'@typescript-eslint/no-misused-new': 'error',
'@typescript-eslint/no-misused-promises': 'error',
Expand Down

0 comments on commit 75a9d51

Please sign in to comment.