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

Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions packages/eslint-plugin/docs/rules/prefer-literal-enum-member.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ This rule reports when an enum member is given a value that is not a literal.

```ts
const str = 'Test';
const string1 = 'string1';
const string2 = 'string2';

enum Invalid {
A = str, // Variable assignment
B = {}, // Object assignment
C = `A template literal string`, // Template literal
D = new Set(1, 2, 3), // Constructor in assignment
E = 2 + 2, // Expression assignment
B = `Interpolates ${string1} and ${string2}`, // Template literal with interpolation
C = 2 + 2, // Expression assignment
D = C, // Assignment to another enum member
}
```

Expand All @@ -52,11 +54,10 @@ enum Invalid {

```ts
enum Valid {
A,
A, // No initializer; initialized with ascending integers starting from 0
B = 'TestStr', // A regular string
C = 4, // A number
D = null,
E = /some_regex/,
C = `A template literal string`, // A template literal without interpolation
D = 4, // A number
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default createRule({
requiresTypeChecking: false,
},
messages: {
notLiteral: `Explicit enum value must only be a literal value (string, number, boolean, etc).`,
notLiteral: `Explicit enum value must only be a literal value (string or number).`,
},
schema: [
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading