Skip to content

Move rules settings to ESLint shared config: part 5 - refactor consistent-data-testid rule #248

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

Merged
merged 19 commits into from
Nov 3, 2020
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/rules/consistent-data-testid.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getDocsUrl } from '../utils';
import { ESLintUtils, TSESTree } from '@typescript-eslint/experimental-utils';
import { ESLintUtils } from '@typescript-eslint/experimental-utils';
import { isJSXAttribute, isLiteral } from '../node-utils';

export const RULE_NAME = 'consistent-data-testid';
Expand All @@ -13,6 +13,11 @@ type Options = [

const FILENAME_PLACEHOLDER = '{fileName}';

/**
* This rule is not created with `createTestingLibraryRule` since:
* - it doesn't need any detection helper
* - it doesn't apply to testing files but component files
*/
export default ESLintUtils.RuleCreator(getDocsUrl)<Options, MessageIds>({
name: RULE_NAME,
meta: {
Expand Down Expand Up @@ -89,7 +94,7 @@ export default ESLintUtils.RuleCreator(getDocsUrl)<Options, MessageIds>({
}

return {
[`JSXIdentifier`]: (node: TSESTree.JSXIdentifier) => {
JSXIdentifier: (node) => {
if (
!isJSXAttribute(node.parent) ||
!isLiteral(node.parent.value) ||
Expand Down