-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 'Symbol.toStringTag' into every exported class
- Loading branch information
1 parent
9a04b4c
commit 2987b6f
Showing
8 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
|
||
module.exports = function requireToStringTag(context) { | ||
const sourceCode = context.getSourceCode(); | ||
|
||
return { | ||
'ExportNamedDeclaration > ClassDeclaration': (classNode) => { | ||
const hasToStringTag = classNode.body.body.some((property) => { | ||
if (property.type !== 'MethodDefinition' || property.kind !== 'get') { | ||
return false; | ||
} | ||
const keyText = sourceCode.getText(property.key); | ||
return keyText === 'Symbol.toStringTag'; | ||
}); | ||
|
||
if (!hasToStringTag) { | ||
context.report({ | ||
node: classNode, | ||
message: | ||
'All exported classes required to have [Symbol.toStringTag] method', | ||
}); | ||
} | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,10 @@ export class Lexer { | |
} | ||
return token; | ||
} | ||
|
||
get [Symbol.toStringTag]() { | ||
return 'Lexer'; | ||
} | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters