Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bb70949

Browse files
committed
fix: typos, use NonComputedName types
1 parent 888c495 commit bb70949

File tree

1 file changed

+41
-44
lines changed

1 file changed

+41
-44
lines changed

packages/eslint-plugin/src/rules/naming-convention.ts

Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ enum PredefinedFormats {
2626
}
2727
type PredefinedFormatsString = keyof typeof PredefinedFormats;
2828

29-
enum UnderscroreOptions {
29+
enum UnderscoreOptions {
3030
forbid = 1 << 0,
3131
allow = 1 << 1,
3232
require = 1 << 2,
3333
}
34-
type UnderscroreOptionsString = keyof typeof UnderscroreOptions;
34+
type UnderscoreOptionsString = keyof typeof UnderscoreOptions;
3535

3636
enum Selectors {
3737
// variableLike
@@ -99,8 +99,8 @@ type TypeModifiersString = keyof typeof TypeModifiers;
9999
interface Selector {
100100
// format options
101101
format: PredefinedFormatsString[];
102-
leadingUnderscore?: UnderscroreOptionsString;
103-
trailingUnderscore?: UnderscroreOptionsString;
102+
leadingUnderscore?: UnderscoreOptionsString;
103+
trailingUnderscore?: UnderscoreOptionsString;
104104
prefix?: string[];
105105
suffix?: string[];
106106
// selector options
@@ -111,8 +111,8 @@ interface Selector {
111111
}
112112
interface NormalizedSelector {
113113
// format options
114-
leadingUnderscore: UnderscroreOptions | null;
115-
trailingUnderscore: UnderscroreOptions | null;
114+
leadingUnderscore: UnderscoreOptions | null;
115+
trailingUnderscore: UnderscoreOptions | null;
116116
prefix: string[] | null;
117117
suffix: string[] | null;
118118
format: PredefinedFormats[];
@@ -136,7 +136,7 @@ type Options = Selector[];
136136

137137
const UNDERSCORE_SCHEMA: JSONSchema.JSONSchema4 = {
138138
type: 'string',
139-
enum: util.getEnumNames(UnderscroreOptions),
139+
enum: util.getEnumNames(UnderscoreOptions),
140140
};
141141
const PREFIX_SUFFIX_SCHEMA: JSONSchema.JSONSchema4 = {
142142
type: 'array',
@@ -336,27 +336,22 @@ export default util.createRule<Options, MessageIds>({
336336
const validators = parseOptions(context);
337337

338338
function handleMember(
339-
validator: ValidatiorFunction | null,
339+
validator: ValidatorFunction | null,
340340
node:
341-
| TSESTree.Property
342-
| TSESTree.ClassProperty
343-
| TSESTree.TSAbstractClassProperty
344-
| TSESTree.TSPropertySignature
345-
| TSESTree.MethodDefinition
346-
| TSESTree.TSAbstractMethodDefinition
347-
| TSESTree.TSMethodSignature,
341+
| TSESTree.PropertyNonComputedName
342+
| TSESTree.ClassPropertyNonComputedName
343+
| TSESTree.TSAbstractClassPropertyNonComputedName
344+
| TSESTree.TSPropertySignatureNonComputedName
345+
| TSESTree.MethodDefinitionNonComputedName
346+
| TSESTree.TSAbstractMethodDefinitionNonComputedName
347+
| TSESTree.TSMethodSignatureNonComputedName,
348348
modifiers: Set<Modifiers>,
349349
): void {
350350
if (!validator) {
351351
return;
352352
}
353353

354354
const key = node.key;
355-
/* istanbul ignore if */ if (!util.isLiteralOrIdentifier(key)) {
356-
// shouldn't happen due to the selectors that are used
357-
return;
358-
}
359-
360355
validator(key, modifiers);
361356
}
362357

@@ -479,7 +474,7 @@ export default util.createRule<Options, MessageIds>({
479474
// #region property
480475

481476
'Property[computed = false][kind = "init"][value.type != "ArrowFunctionExpression"][value.type != "FunctionExpression"][value.type != "TSEmptyBodyFunctionExpression"]'(
482-
node: TSESTree.Property,
477+
node: TSESTree.PropertyNonComputedName,
483478
): void {
484479
const modifiers = new Set<Modifiers>([Modifiers.public]);
485480
handleMember(validators.property, node, modifiers);
@@ -489,14 +484,16 @@ export default util.createRule<Options, MessageIds>({
489484
'ClassProperty[computed = false][value.type != "ArrowFunctionExpression"][value.type != "FunctionExpression"][value.type != "TSEmptyBodyFunctionExpression"]',
490485
'TSAbstractClassProperty[computed = false][value.type != "ArrowFunctionExpression"][value.type != "FunctionExpression"][value.type != "TSEmptyBodyFunctionExpression"]',
491486
].join(', ')](
492-
node: TSESTree.ClassProperty | TSESTree.TSAbstractClassProperty,
487+
node:
488+
| TSESTree.ClassPropertyNonComputedName
489+
| TSESTree.TSAbstractClassPropertyNonComputedName,
493490
): void {
494491
const modifiers = getMemberModifiers(node);
495492
handleMember(validators.property, node, modifiers);
496493
},
497494

498495
'TSPropertySignature[computed = false]'(
499-
node: TSESTree.TSPropertySignature,
496+
node: TSESTree.TSPropertySignatureNonComputedName,
500497
): void {
501498
const modifiers = new Set<Modifiers>([Modifiers.public]);
502499
if (node.readonly) {
@@ -516,7 +513,9 @@ export default util.createRule<Options, MessageIds>({
516513
'Property[computed = false][kind = "init"][value.type = "TSEmptyBodyFunctionExpression"]',
517514
'TSMethodSignature[computed = false]',
518515
].join(', ')](
519-
node: TSESTree.Property | TSESTree.TSMethodSignature,
516+
node:
517+
| TSESTree.PropertyNonComputedName
518+
| TSESTree.TSMethodSignatureNonComputedName,
520519
): void {
521520
const modifiers = new Set<Modifiers>([Modifiers.public]);
522521
handleMember(validators.method, node, modifiers);
@@ -533,10 +532,10 @@ export default util.createRule<Options, MessageIds>({
533532
'TSAbstractMethodDefinition[computed = false][kind = "method"]',
534533
].join(', ')](
535534
node:
536-
| TSESTree.ClassProperty
537-
| TSESTree.TSAbstractClassProperty
538-
| TSESTree.MethodDefinition
539-
| TSESTree.TSAbstractMethodDefinition,
535+
| TSESTree.ClassPropertyNonComputedName
536+
| TSESTree.TSAbstractClassPropertyNonComputedName
537+
| TSESTree.MethodDefinitionNonComputedName
538+
| TSESTree.TSAbstractMethodDefinitionNonComputedName,
540539
): void {
541540
const modifiers = getMemberModifiers(node);
542541
handleMember(validators.method, node, modifiers);
@@ -549,15 +548,15 @@ export default util.createRule<Options, MessageIds>({
549548
[[
550549
'Property[computed = false][kind = "get"]',
551550
'Property[computed = false][kind = "set"]',
552-
].join(', ')](node: TSESTree.Property): void {
551+
].join(', ')](node: TSESTree.PropertyNonComputedName): void {
553552
const modifiers = new Set<Modifiers>([Modifiers.public]);
554553
handleMember(validators.accessor, node, modifiers);
555554
},
556555

557556
[[
558557
'MethodDefinition[computed = false][kind = "get"]',
559558
'MethodDefinition[computed = false][kind = "set"]',
560-
].join(', ')](node: TSESTree.MethodDefinition): void {
559+
].join(', ')](node: TSESTree.MethodDefinitionNonComputedName): void {
561560
const modifiers = getMemberModifiers(node);
562561
handleMember(validators.accessor, node, modifiers);
563562
},
@@ -566,18 +565,16 @@ export default util.createRule<Options, MessageIds>({
566565

567566
// #region enumMember
568567

569-
TSEnumMember(node): void {
568+
// computed is optional, so can't do [computed = false]
569+
'TSEnumMember[computed != true]'(
570+
node: TSESTree.TSEnumMemberNonComputedName,
571+
): void {
570572
const validator = validators.enumMember;
571573
if (!validator) {
572574
return;
573575
}
574576

575577
const id = node.id;
576-
/* istanbul ignore if */ if (!util.isLiteralOrIdentifier(id)) {
577-
// shouldn't happen in reality because it's not semantically valid code
578-
return;
579-
}
580-
581578
validator(id);
582579
},
583580

@@ -586,7 +583,7 @@ export default util.createRule<Options, MessageIds>({
586583
// #region class
587584

588585
'ClassDeclaration, ClassExpression'(
589-
node: TSESTree.ClassDeclaration | TSESTree.ClassDeclaration,
586+
node: TSESTree.ClassDeclaration | TSESTree.ClassExpression,
590587
): void {
591588
const validator = validators.class;
592589
if (!validator) {
@@ -716,11 +713,11 @@ function getIdentifiersFromPattern(
716713
}
717714
}
718715

719-
type ValidatiorFunction = (
716+
type ValidatorFunction = (
720717
node: TSESTree.Identifier | TSESTree.Literal,
721718
modifiers?: Set<Modifiers>,
722719
) => void;
723-
type ParsedOptions = Record<SelectorsString, null | ValidatiorFunction>;
720+
type ParsedOptions = Record<SelectorsString, null | ValidatorFunction>;
724721
type Context = TSESLint.RuleContext<MessageIds, Options>;
725722
function parseOptions(context: Context): ParsedOptions {
726723
const normalizedOptions = context.options.map(opt => normalizeOption(opt));
@@ -863,11 +860,11 @@ function createValidator(
863860
: (): string => name.slice(0, -1);
864861

865862
switch (option) {
866-
case UnderscroreOptions.allow:
863+
case UnderscoreOptions.allow:
867864
// no check - the user doesn't care if it's there or not
868865
break;
869866

870-
case UnderscroreOptions.forbid:
867+
case UnderscoreOptions.forbid:
871868
if (hasUnderscore) {
872869
context.report({
873870
node,
@@ -881,7 +878,7 @@ function createValidator(
881878
}
882879
break;
883880

884-
case UnderscroreOptions.require:
881+
case UnderscoreOptions.require:
885882
if (!hasUnderscore) {
886883
context.report({
887884
node,
@@ -1116,11 +1113,11 @@ function normalizeOption(option: Selector): NormalizedSelector {
11161113
// format options
11171114
leadingUnderscore:
11181115
option.leadingUnderscore !== undefined
1119-
? UnderscroreOptions[option.leadingUnderscore]
1116+
? UnderscoreOptions[option.leadingUnderscore]
11201117
: null,
11211118
trailingUnderscore:
11221119
option.trailingUnderscore !== undefined
1123-
? UnderscroreOptions[option.trailingUnderscore]
1120+
? UnderscoreOptions[option.trailingUnderscore]
11241121
: null,
11251122
prefix: option.prefix ?? null,
11261123
suffix: option.suffix ?? null,

0 commit comments

Comments
 (0)