Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: refine typescript-eslint config #705

Merged
merged 5 commits into from Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
60 changes: 60 additions & 0 deletions .eslintrc.js
@@ -0,0 +1,60 @@
module.exports = {
root: true,
extends: [
'kentcdodds',
'plugin:jest/recommended',
'plugin:jest-formatting/recommended',
'prettier',
],
rules: {
// Base
'max-lines-per-function': 'off',
'no-restricted-imports': [
'error',
{
patterns: [
{
group: ['@typescript-eslint/utils/dist/*'],
message: 'Import from `@typescript-eslint/utils` instead.',
},
],
},
],

// Import
'import/order': [
'warn',
{
groups: ['builtin', 'external', 'parent', 'sibling', 'index'],
'newlines-between': 'always',
alphabetize: {
order: 'asc',
caseInsensitive: false,
},
},
],
},
overrides: [
{
// TypeScript
files: ['**/*.ts?(x)'],
parser: '@typescript-eslint/parser',
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./tsconfig.eslint.json'],
},
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
],
rules: {
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-unused-vars': [
'warn',
{ argsIgnorePattern: '^_' },
],
'@typescript-eslint/no-use-before-define': 'off',
},
},
],
};
57 changes: 0 additions & 57 deletions .eslintrc.json

This file was deleted.

9 changes: 6 additions & 3 deletions lib/rules/no-await-sync-events.ts
Expand Up @@ -151,13 +151,16 @@ export default createTestingLibraryRule<Options, MessageIds>({
return;
}

const eventModuleName = getPropertyIdentifierNode(node)?.name;
const eventFullName = eventModuleName
? `${eventModuleName}.${simulateEventFunctionName}`
: simulateEventFunctionName;

context.report({
node,
messageId: 'noAwaitSyncEvents',
data: {
name: `${
getPropertyIdentifierNode(node)?.name
}.${simulateEventFunctionName}`,
name: eventFullName,
},
});
},
Expand Down
17 changes: 13 additions & 4 deletions lib/rules/no-dom-import.ts
Expand Up @@ -12,13 +12,22 @@ const DOM_TESTING_LIBRARY_MODULES = [
'@testing-library/dom',
];

const correctModuleNameByFramework = {
const CORRECT_MODULE_NAME_BY_FRAMEWORK: Record<
'angular' | 'marko' | string,
string | undefined
> = {
angular: '@testing-library/angular', // ATL is *always* called `@testing-library/angular`
marko: '@marko/testing-library', // Marko TL is called `@marko/testing-library`
};
const getCorrectModuleName = (moduleName: string, framework: string): string =>
correctModuleNameByFramework[framework] ||
moduleName.replace('dom', framework);
const getCorrectModuleName = (
moduleName: string,
framework: string
): string => {
return (
CORRECT_MODULE_NAME_BY_FRAMEWORK[framework] ??
moduleName.replace('dom', framework)
);
};

export default createTestingLibraryRule<Options, MessageIds>({
name: RULE_NAME,
Expand Down
4 changes: 3 additions & 1 deletion lib/rules/no-wait-for-snapshot.ts
Expand Up @@ -68,7 +68,9 @@ export default createTestingLibraryRule<Options, MessageIds>({
}

return {
[`Identifier[name=${SNAPSHOT_REGEXP}]`](node: TSESTree.Identifier) {
[`Identifier[name=${String(SNAPSHOT_REGEXP)}]`](
node: TSESTree.Identifier
) {
const closestAsyncUtil = getClosestAsyncUtil(node);
if (closestAsyncUtil === null) {
return;
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/file-import.ts
@@ -1,7 +1,7 @@
// Copied from https://github.com/babel/babel/blob/b35c78f08dd854b08575fc66ebca323fdbc59dab/packages/babel-helpers/src/helpers.js#L615-L619
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const interopRequireDefault = <T>(obj: any): { default: T } =>
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-return
obj?.__esModule ? obj : { default: obj };

export const importDefault = <T>(moduleName: string): T =>
Expand Down
1 change: 1 addition & 0 deletions tests/index.test.ts
Expand Up @@ -67,6 +67,7 @@ it('should export configs that refer to actual rules', () => {
expect(rule.startsWith(ruleNamePrefix)).toBe(true);
expect(ruleNames).toContain(ruleName);

// eslint-disable-next-line @typescript-eslint/no-unsafe-return
Belco90 marked this conversation as resolved.
Show resolved Hide resolved
expect(() => require(`../lib/rules/${ruleName}`)).not.toThrow();
});
});