Skip to content

Commit

Permalink
fix: Apply ESLint to .ts files (#602)
Browse files Browse the repository at this point in the history
* fix: add missing `files` property

* fix: lint
  • Loading branch information
y-hsgw authored Dec 19, 2024
1 parent 342ce00 commit 085e320
Show file tree
Hide file tree
Showing 58 changed files with 832 additions and 850 deletions.
20 changes: 10 additions & 10 deletions eslint-remote-tester.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import parser from '@typescript-eslint/parser';
import type { Config } from 'eslint-remote-tester';
import parser from '@typescript-eslint/parser'
import type { Config } from 'eslint-remote-tester'
import {
getPathIgnorePattern,
getRepositories,
} from 'eslint-remote-tester-repositories';
import vitest from './dist/index.mjs';
getRepositories
} from 'eslint-remote-tester-repositories'
import vitest from './dist/index.mjs'

export default {
repositories: getRepositories(),
Expand All @@ -17,8 +17,8 @@ export default {
vitest.configs.all,
{
languageOptions: {
parser,
},
},
] as Config['eslintConfig'],
} satisfies Config;
parser
}
}
] as Config['eslintConfig']
} satisfies Config
10 changes: 7 additions & 3 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@ const styleConfigs = stylistic.configs.customize({
commaDangle: 'never'
})

/** @type {import("eslint").Linter.Config[]} */
export default [
eslintPlugin.configs['flat/recommended'],
vitest.configs.recommended,
vitest.configs.env,
{
files: ['**/*.ts'],
languageOptions: {
parser
}
},
{
ignores: ['dist/**/*', '**/*.md'],
plugins: {
Expand All @@ -29,9 +36,6 @@ export default [
vitest: {
typecheck: true
}
},
languageOptions: {
parser
}
}
]
2 changes: 1 addition & 1 deletion scripts/chain-permutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const DEPTH = 3

const allPermutations: string[] = []

const depths = (maxDepth:number) => Array.from({ length: maxDepth }, (_, i) => i)
const depths = (maxDepth: number) => Array.from({ length: maxDepth }, (_, i) => i)

data.forEach((q) => {
q.names.forEach((name) => {
Expand Down
22 changes: 11 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import preferEach, { RULE_NAME as preferEachName } from './rules/prefer-each'
import preferHooksOnTop, { RULE_NAME as preferHooksOnTopName } from './rules/prefer-hooks-on-top'
import preferHooksInOrder, { RULE_NAME as preferHooksInOrderName } from './rules/prefer-hooks-in-order'
import preferMockPromiseShorthand, { RULE_NAME as preferMockPromiseShortHandName } from './rules/prefer-mock-promise-shorthand'
import preferViMocked, { RULE_NAME as preferViMockedName } from "./rules/prefer-vi-mocked";
import preferViMocked, { RULE_NAME as preferViMockedName } from './rules/prefer-vi-mocked'
import preferSnapshotHint, { RULE_NAME as preferSnapshotHintName } from './rules/prefer-snapshot-hint'
import validDescribeCallback, { RULE_NAME as validDescribeCallbackName } from './rules/valid-describe-callback'
import requireTopLevelDescribe, { RULE_NAME as requireTopLevelDescribeName } from './rules/require-top-level-describe'
Expand All @@ -53,14 +53,14 @@ import preferSpyOn, { RULE_NAME as preferSpyOnName } from './rules/prefer-spy-on
import preferComparisonMatcher, { RULE_NAME as preferComparisonMatcherName } from './rules/prefer-comparison-matcher'
import preferToContain, { RULE_NAME as preferToContainName } from './rules/prefer-to-contain'
import preferExpectAssertions, { RULE_NAME as preferExpectAssertionsName } from './rules/prefer-expect-assertions'
import paddingAroundAfterAllBlocks, { RULE_NAME as paddingAroundAfterAllBlocksName } from "./rules/padding-around-after-all-blocks"
import paddingAroundAfterEachBlocks, { RULE_NAME as paddingAroundAfterEachBlocksName } from "./rules/padding-around-after-each-blocks"
import paddingAroundAll, { RULE_NAME as paddingAroundAllName } from "./rules/padding-around-all"
import paddingAroundBeforeAllBlocks, { RULE_NAME as paddingAroundBeforeAllBlocksName } from "./rules/padding-around-before-all-blocks"
import paddingAroundBeforeEachBlocks, { RULE_NAME as paddingAroundBeforeEachBlocksName } from "./rules/padding-around-before-each-blocks"
import paddingAroundDescribeBlocks, { RULE_NAME as paddingAroundDescribeBlocksName } from "./rules/padding-around-describe-blocks"
import paddingAroundExpectGroups, { RULE_NAME as paddingAroundExpectGroupsName } from "./rules/padding-around-expect-groups"
import paddingAroundTestBlocks, { RULE_NAME as paddingAroundTestBlocksName } from "./rules/padding-around-test-blocks"
import paddingAroundAfterAllBlocks, { RULE_NAME as paddingAroundAfterAllBlocksName } from './rules/padding-around-after-all-blocks'
import paddingAroundAfterEachBlocks, { RULE_NAME as paddingAroundAfterEachBlocksName } from './rules/padding-around-after-each-blocks'
import paddingAroundAll, { RULE_NAME as paddingAroundAllName } from './rules/padding-around-all'
import paddingAroundBeforeAllBlocks, { RULE_NAME as paddingAroundBeforeAllBlocksName } from './rules/padding-around-before-all-blocks'
import paddingAroundBeforeEachBlocks, { RULE_NAME as paddingAroundBeforeEachBlocksName } from './rules/padding-around-before-each-blocks'
import paddingAroundDescribeBlocks, { RULE_NAME as paddingAroundDescribeBlocksName } from './rules/padding-around-describe-blocks'
import paddingAroundExpectGroups, { RULE_NAME as paddingAroundExpectGroupsName } from './rules/padding-around-expect-groups'
import paddingAroundTestBlocks, { RULE_NAME as paddingAroundTestBlocksName } from './rules/padding-around-test-blocks'
import validExpectInPromise, { RULE_NAME as validExpectInPromiseName } from './rules/valid-expect-in-promise'

const createConfig = <R extends Linter.RulesRecord>(rules: R) => (
Expand All @@ -70,8 +70,8 @@ const createConfig = <R extends Linter.RulesRecord>(rules: R) => (
[`vitest/${ruleName}`]: rules[ruleName]
}
}, {})) as {
[K in keyof R as `vitest/${Extract<K, string>}`]: R[K]
}
[K in keyof R as `vitest/${Extract<K, string>}`]: R[K]
}

const createConfigLegacy = (rules: Record<string, string>) => ({
plugins: ['@vitest'],
Expand Down
4 changes: 2 additions & 2 deletions src/rules/consistent-test-filename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ export default createEslintRule<
additionalProperties: false,
properties: {
pattern: {
//@ts-ignore
// @ts-ignore
format: 'regex',
default: defaultPattern.source
},
allTestPattern: {
//@ts-ignore
// @ts-ignore
format: 'regex',
default: defaultTestsPattern.source
}
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default createEslintRule<
properties: {
allow: {
type: 'array',
//@ts-ignore
// @ts-ignore
contains: ['beforeAll', 'beforeEach', 'afterAll', 'afterEach']
}
},
Expand Down
8 changes: 4 additions & 4 deletions src/rules/no-standalone-expect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ export default createEslintRule<Options, MESSAGE_IDS>({
{
properties: {
additionaltestblockfunctions: {
//@ts-ignore
// @ts-ignore
type: 'array',
//@ts-ignore
// @ts-ignore
items: { type: `string` }
}
},
Expand All @@ -74,8 +74,8 @@ export default createEslintRule<Options, MESSAGE_IDS>({
if (vitestFnCall?.type === 'expect') {
if (vitestFnCall.head.node.parent?.type === AST_NODE_TYPES.MemberExpression
&& vitestFnCall.members.length === 1 && !['assertions', 'hasAssertions'].includes(
getAccessorValue(vitestFnCall.members[0])
))
getAccessorValue(vitestFnCall.members[0])
))
return

const parent = callStack[callStack.length - 1]
Expand Down
2 changes: 1 addition & 1 deletion src/rules/padding-around-after-all-blocks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Config, PaddingType, StatementType, createPaddingRule } from "../utils/padding"
import { Config, PaddingType, StatementType, createPaddingRule } from '../utils/padding'

export const RULE_NAME = 'padding-around-after-all-blocks'

Expand Down
2 changes: 1 addition & 1 deletion src/rules/padding-around-after-each-blocks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Config, PaddingType, StatementType, createPaddingRule } from "../utils/padding";
import { Config, PaddingType, StatementType, createPaddingRule } from '../utils/padding'

export const RULE_NAME = 'padding-around-after-each-blocks'

Expand Down
23 changes: 11 additions & 12 deletions src/rules/padding-around-all.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@

import { config as paddingAroundAfterAllBlocksConfig } from './padding-around-after-all-blocks';
import { config as paddingAroundAfterEachBlocksConfig } from './padding-around-after-each-blocks';
import { config as paddingAroundBeforeAllBlocksConfig } from './padding-around-before-all-blocks';
import { config as paddingAroundBeforeEachBlocksConfig } from './padding-around-before-each-blocks';
import { config as paddingAroundDescribeBlocksConfig } from './padding-around-describe-blocks';
import { config as paddingAroundExpectGroupsConfig } from './padding-around-expect-groups';
import { config as paddingAroundTestBlocksConfig } from './padding-around-test-blocks';
import { createPaddingRule } from '../utils/padding';
import { config as paddingAroundAfterAllBlocksConfig } from './padding-around-after-all-blocks'
import { config as paddingAroundAfterEachBlocksConfig } from './padding-around-after-each-blocks'
import { config as paddingAroundBeforeAllBlocksConfig } from './padding-around-before-all-blocks'
import { config as paddingAroundBeforeEachBlocksConfig } from './padding-around-before-each-blocks'
import { config as paddingAroundDescribeBlocksConfig } from './padding-around-describe-blocks'
import { config as paddingAroundExpectGroupsConfig } from './padding-around-expect-groups'
import { config as paddingAroundTestBlocksConfig } from './padding-around-test-blocks'
import { createPaddingRule } from '../utils/padding'

export const RULE_NAME = 'padding-around-all'

Expand All @@ -20,6 +19,6 @@ export default createPaddingRule(
...paddingAroundBeforeEachBlocksConfig,
...paddingAroundDescribeBlocksConfig,
...paddingAroundExpectGroupsConfig,
...paddingAroundTestBlocksConfig,
],
);
...paddingAroundTestBlocksConfig
]
)
2 changes: 1 addition & 1 deletion src/rules/padding-around-before-all-blocks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Config, PaddingType, StatementType, createPaddingRule } from "../utils/padding";
import { Config, PaddingType, StatementType, createPaddingRule } from '../utils/padding'

export const RULE_NAME = 'padding-around-before-all-blocks'

Expand Down
14 changes: 7 additions & 7 deletions src/rules/padding-around-before-each-blocks.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { PaddingType, StatementType, createPaddingRule } from '../utils/padding';
import { PaddingType, StatementType, createPaddingRule } from '../utils/padding'

export const RULE_NAME = 'padding-around-before-each-blocks'

export const config = [
{
paddingType: PaddingType.Always,
prevStatementType: StatementType.Any,
nextStatementType: StatementType.BeforeEachToken,
nextStatementType: StatementType.BeforeEachToken
},
{
paddingType: PaddingType.Always,
prevStatementType: StatementType.BeforeEachToken,
nextStatementType: StatementType.Any,
},
];
nextStatementType: StatementType.Any
}
]

export default createPaddingRule(
RULE_NAME,
'Enforce padding around `beforeEach` blocks',
config,
);
config
)
18 changes: 9 additions & 9 deletions src/rules/padding-around-describe-blocks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Config, PaddingType, StatementType, createPaddingRule } from '../utils/padding';
import { Config, PaddingType, StatementType, createPaddingRule } from '../utils/padding'

export const RULE_NAME = 'padding-around-describe-blocks'

Expand All @@ -9,22 +9,22 @@ export const config: Config[] = [
nextStatementType: [
StatementType.DescribeToken,
StatementType.FdescribeToken,
StatementType.XdescribeToken,
],
StatementType.XdescribeToken
]
},
{
paddingType: PaddingType.Always,
prevStatementType: [
StatementType.DescribeToken,
StatementType.FdescribeToken,
StatementType.XdescribeToken,
StatementType.XdescribeToken
],
nextStatementType: StatementType.Any,
},
];
nextStatementType: StatementType.Any
}
]

export default createPaddingRule(
RULE_NAME,
'Enforce padding around `describe` blocks',
config,
);
config
)
22 changes: 11 additions & 11 deletions src/rules/padding-around-expect-groups.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
import { Config, PaddingType, StatementType, createPaddingRule } from "../utils/padding";
import { Config, PaddingType, StatementType, createPaddingRule } from '../utils/padding'

export const RULE_NAME = 'padding-around-expect-groups'

export const config: Config[] = [
{
paddingType: PaddingType.Always,
prevStatementType: StatementType.Any,
nextStatementType: StatementType.ExpectToken,
nextStatementType: StatementType.ExpectToken
},
{
paddingType: PaddingType.Always,
prevStatementType: StatementType.ExpectToken,
nextStatementType: StatementType.Any,
nextStatementType: StatementType.Any
},
{
paddingType: PaddingType.Any,
prevStatementType: StatementType.ExpectToken,
nextStatementType: StatementType.ExpectToken,
nextStatementType: StatementType.ExpectToken
},
{
paddingType: PaddingType.Always,
prevStatementType: StatementType.Any,
nextStatementType: StatementType.ExpectTypeOfToken,
nextStatementType: StatementType.ExpectTypeOfToken
},
{
paddingType: PaddingType.Always,
prevStatementType: StatementType.ExpectTypeOfToken,
nextStatementType: StatementType.Any,
nextStatementType: StatementType.Any
},
{
paddingType: PaddingType.Any,
prevStatementType: StatementType.ExpectTypeOfToken,
nextStatementType: StatementType.ExpectTypeOfToken,
},
];
nextStatementType: StatementType.ExpectTypeOfToken
}
]

export default createPaddingRule(
RULE_NAME,
'Enforce padding around `expect` groups',
config,
);
config
)
18 changes: 9 additions & 9 deletions src/rules/padding-around-test-blocks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PaddingType, StatementType, createPaddingRule } from '../utils/padding';
import { PaddingType, StatementType, createPaddingRule } from '../utils/padding'

export const RULE_NAME = 'padding-around-test-blocks'

Expand All @@ -11,8 +11,8 @@ export const config = [
StatementType.ItToken,
StatementType.FitToken,
StatementType.XitToken,
StatementType.XtestToken,
],
StatementType.XtestToken
]
},
{
paddingType: PaddingType.Always,
Expand All @@ -21,14 +21,14 @@ export const config = [
StatementType.ItToken,
StatementType.FitToken,
StatementType.XitToken,
StatementType.XtestToken,
StatementType.XtestToken
],
nextStatementType: StatementType.Any,
},
];
nextStatementType: StatementType.Any
}
]

export default createPaddingRule(
RULE_NAME,
'Enforce padding around afterAll blocks',
config,
);
config
)
2 changes: 1 addition & 1 deletion src/rules/prefer-comparison-matcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export default createEslintRule<Options, MESSAGE_IDS>({
),
fixer.replaceTextRange(
[expectCallEnd, matcher.parent.range[1]],
`${modifierText}.${preferredMatcher}`
`${modifierText}.${preferredMatcher}`
),
fixer.replaceText(
matcherArg,
Expand Down
2 changes: 1 addition & 1 deletion src/rules/prefer-equality-matcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default createEslintRule<Options, MESSAGE_IDS>({
),
fixer.replaceTextRange(
[expectCallEnd, matcher.parent.range[1]],
`${modifierText}.${equalityMatcher}`
`${modifierText}.${equalityMatcher}`
),
fixer.replaceText(
matcherArg,
Expand Down
Loading

0 comments on commit 085e320

Please sign in to comment.