Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

Commit

Permalink
[typescript/prefer-pascal-case-enum] Fix an issue with undefined name (
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandcote authored Feb 11, 2020
1 parent 3188c2c commit d7a23a9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [Unreleased]

- remove `no-vague-titles` because the rule was adopted into `eslint-plugin-jest`'s `valid-title` rule. See [the `valid-title` documentation](https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/valid-title.md#disallowedwords)
- Fixed an issue with `typescript/prefer-pascal-case-enum` when you had enum with key as string. ([517](https://github.com/Shopify/eslint-plugin-shopify/pull/517))

## [34.0.1] - 2019-01-13

Expand Down
13 changes: 7 additions & 6 deletions lib/rules/typescript/prefer-pascal-case-enums.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ module.exports = {
},
create(context) {
function report(node) {
const {name} = node;

const {name, value} = node;
const identifier = name || value;
context.report({
node,
message: `Enum '{{name}}' should use Pascal case.`,
data: {name},
message: `Enum '{{identifier}}' should use Pascal case.`,
data: {identifier},
});
}

Expand All @@ -38,6 +38,7 @@ module.exports = {
},
};

function isPascalCase({name}) {
return name === pascalCase(name);
function isPascalCase({name, value}) {
const identifier = name || value;
return identifier != null && identifier === pascalCase(identifier);
}
5 changes: 4 additions & 1 deletion tests/lib/rules/typescript/prefer-pascal-case-enums.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const ruleTester = new RuleTester({

function errorWithName(name) {
return {
type: 'Identifier',
message: `Enum '${name}' should use Pascal case.`,
};
}
Expand Down Expand Up @@ -44,5 +43,9 @@ ruleTester.run('prefer-pascal-case-enums', rule, {
code: `enum SortOrder {MOSTRECENT, least_recent, Newest, Oldest}`,
errors: [errorWithName('MOSTRECENT'), errorWithName('least_recent')],
},
{
code: `enum Example {'foo' = 'bar', '1024x1024' = '1024x1024', Oldest}`,
errors: [errorWithName('foo')],
},
],
});

0 comments on commit d7a23a9

Please sign in to comment.