-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Const enum recommendation Eslint plugin #2246
Open
noahdarveau-MSFT
wants to merge
19
commits into
main
Choose a base branch
from
noahdarveau/custom-eslint-plugin
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
bbbeee5
added custom eslint rule to recommend using const enums
noahdarveau-MSFT 2875a84
changefile
noahdarveau-MSFT 76f12bb
removed commented out code
noahdarveau-MSFT 7307b88
Merge branch 'main' into noahdarveau/custom-eslint-plugin
noahdarveau-MSFT a770c63
Merge branch 'main' into noahdarveau/custom-eslint-plugin
noahdarveau-MSFT 00ad529
Merge branch 'main' into noahdarveau/custom-eslint-plugin
noahdarveau-MSFT 0faa4b3
added eslint ignores to all public non const enums
noahdarveau-MSFT ced650a
Merge branch 'main' into noahdarveau/custom-eslint-plugin
noahdarveau-MSFT 54f7d05
made test enums const
noahdarveau-MSFT 35c7a2b
Merge branch 'main' into noahdarveau/custom-eslint-plugin
noahdarveau-MSFT 0640432
Merge branch 'main' into noahdarveau/custom-eslint-plugin
noahdarveau-MSFT 4c86843
added link to wiki in warning message
noahdarveau-MSFT fd05560
Merge branch 'main' into noahdarveau/custom-eslint-plugin
AE-MS a4e6681
merged main
noahdarveau-MSFT bbdd7a5
added plugin surpression explanation comments
noahdarveau-MSFT bfef846
merged main
noahdarveau-MSFT 1953247
fixed lock file
noahdarveau-MSFT a24007a
Merge branch 'main' into noahdarveau/custom-eslint-plugin
AE-MS 3467499
Merge branch 'main' into noahdarveau/custom-eslint-plugin
noahdarveau-MSFT File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@microsoft-teams-js-6cae075f-47d3-4274-b35a-bbd901a3082b.json
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,7 @@ | ||
{ | ||
"type": "patch", | ||
"comment": "Added an eslint plugin to recommend the use of const enums when possible", | ||
"packageName": "@microsoft/teams-js", | ||
"email": "noahdarveau@microsoft.com", | ||
"dependentChangeType": "patch" | ||
} |
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
4 changes: 4 additions & 0 deletions
4
packages/teams-js/eslint-rules/eslint-plugin-recommend-const-enums/index.js
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,4 @@ | ||
const recommendConstEnumsRule = require('./recommendConstEnums.js'); | ||
|
||
const plugin = { rules: { 'recommend-const-enums': recommendConstEnumsRule } }; | ||
module.exports = plugin; |
16 changes: 16 additions & 0 deletions
16
packages/teams-js/eslint-rules/eslint-plugin-recommend-const-enums/package.json
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,16 @@ | ||
{ | ||
"name": "eslint-plugin-recommend-const-enums", | ||
"version": "0.0.0", | ||
"license": "MIT", | ||
"author": "Noah", | ||
"description": "Recommend using const enums", | ||
"type": "commonjs", | ||
"keywords": [ | ||
"eslint", | ||
"eslint-plugin", | ||
"eslintplugin" | ||
], | ||
"peerDependencies": { | ||
"eslint": ">=5.0.0" | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
packages/teams-js/eslint-rules/eslint-plugin-recommend-const-enums/recommendConstEnums.js
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,30 @@ | ||
module.exports = { | ||
meta: { | ||
type: 'suggestion', | ||
docs: { | ||
description: 'Recommend using const enums if possible to minimize bundle size', | ||
category: 'Best Practices', | ||
recommended: true, | ||
}, | ||
fixable: 'code', | ||
schema: [], | ||
}, | ||
|
||
create: function (context) { | ||
return { | ||
TSEnumDeclaration: function (node) { | ||
const enumName = node.id.name; | ||
const enumType = node.const ? 'const' : 'regular'; | ||
|
||
if (enumType === 'regular') { | ||
context.report({ | ||
node: node, | ||
message: `Please consider if you can use a const enum for ${enumName} to minimize bundle size. If not, add "/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */" to the line above to disable this warning, | ||
as well as a comment explaining why you can't use a const enum. To learn more about why we typically want to use const enums, see https://github.com/OfficeDev/microsoft-teams-library-js/wiki/Notes-on-Enum-Usage.`, | ||
severity: 2, | ||
}); | ||
} | ||
}, | ||
}; | ||
}, | ||
}; |
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol