Skip to content

Commit 762dd1a

Browse files
fix(eslint-plugin): [prefer-literal-enum-member] report a different error message when allowBitwiseExpressions is enabled (#10096)
[prefer-literal-enum-member] report message should reflect bitwise expression option Co-authored-by: Josh Goldberg <git@joshuakgoldberg.com>
1 parent e47d398 commit 762dd1a

3 files changed

Lines changed: 20 additions & 17 deletions

File tree

‎packages/eslint-plugin/src/rules/prefer-literal-enum-member.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default createRule({
1515
},
1616
messages: {
1717
notLiteral: `Explicit enum value must only be a literal value (string or number).`,
18+
notLiteralOrBitwiseExpression: `Explicit enum value must only be a literal value (string or number) or a bitwise expression.`,
1819
},
1920
schema: [
2021
{
@@ -143,7 +144,9 @@ export default createRule({
143144

144145
context.report({
145146
node: node.id,
146-
messageId: 'notLiteral',
147+
messageId: allowBitwiseExpressions
148+
? 'notLiteralOrBitwiseExpression'
149+
: 'notLiteral',
147150
});
148151
},
149152
};

‎packages/eslint-plugin/tests/docs-eslint-output-snapshots/prefer-literal-enum-member.shot‎

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/eslint-plugin/tests/rules/prefer-literal-enum-member.test.ts‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -419,37 +419,37 @@ enum Foo {
419419
{
420420
column: 3,
421421
line: 4,
422-
messageId: 'notLiteral',
422+
messageId: 'notLiteralOrBitwiseExpression',
423423
},
424424
{
425425
column: 3,
426426
line: 5,
427-
messageId: 'notLiteral',
427+
messageId: 'notLiteralOrBitwiseExpression',
428428
},
429429
{
430430
column: 3,
431431
line: 6,
432-
messageId: 'notLiteral',
432+
messageId: 'notLiteralOrBitwiseExpression',
433433
},
434434
{
435435
column: 3,
436436
line: 7,
437-
messageId: 'notLiteral',
437+
messageId: 'notLiteralOrBitwiseExpression',
438438
},
439439
{
440440
column: 3,
441441
line: 8,
442-
messageId: 'notLiteral',
442+
messageId: 'notLiteralOrBitwiseExpression',
443443
},
444444
{
445445
column: 3,
446446
line: 9,
447-
messageId: 'notLiteral',
447+
messageId: 'notLiteralOrBitwiseExpression',
448448
},
449449
{
450450
column: 3,
451451
line: 10,
452-
messageId: 'notLiteral',
452+
messageId: 'notLiteralOrBitwiseExpression',
453453
},
454454
],
455455
options: [{ allowBitwiseExpressions: true }],
@@ -467,12 +467,12 @@ enum Foo {
467467
{
468468
column: 3,
469469
line: 5,
470-
messageId: 'notLiteral',
470+
messageId: 'notLiteralOrBitwiseExpression',
471471
},
472472
{
473473
column: 3,
474474
line: 6,
475-
messageId: 'notLiteral',
475+
messageId: 'notLiteralOrBitwiseExpression',
476476
},
477477
],
478478
options: [{ allowBitwiseExpressions: true }],

0 commit comments

Comments
 (0)