Skip to content
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
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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 Apr 1, 2024
2875a84
changefile
noahdarveau-MSFT Apr 1, 2024
76f12bb
removed commented out code
noahdarveau-MSFT Apr 1, 2024
7307b88
Merge branch 'main' into noahdarveau/custom-eslint-plugin
noahdarveau-MSFT Apr 5, 2024
a770c63
Merge branch 'main' into noahdarveau/custom-eslint-plugin
noahdarveau-MSFT Apr 5, 2024
00ad529
Merge branch 'main' into noahdarveau/custom-eslint-plugin
noahdarveau-MSFT Apr 9, 2024
0faa4b3
added eslint ignores to all public non const enums
noahdarveau-MSFT Apr 10, 2024
ced650a
Merge branch 'main' into noahdarveau/custom-eslint-plugin
noahdarveau-MSFT Apr 11, 2024
54f7d05
made test enums const
noahdarveau-MSFT Apr 11, 2024
35c7a2b
Merge branch 'main' into noahdarveau/custom-eslint-plugin
noahdarveau-MSFT Apr 11, 2024
0640432
Merge branch 'main' into noahdarveau/custom-eslint-plugin
noahdarveau-MSFT Apr 15, 2024
4c86843
added link to wiki in warning message
noahdarveau-MSFT Apr 15, 2024
fd05560
Merge branch 'main' into noahdarveau/custom-eslint-plugin
AE-MS Apr 16, 2024
a4e6681
merged main
noahdarveau-MSFT Apr 16, 2024
bbdd7a5
added plugin surpression explanation comments
noahdarveau-MSFT Apr 16, 2024
bfef846
merged main
noahdarveau-MSFT Apr 16, 2024
1953247
fixed lock file
noahdarveau-MSFT Apr 16, 2024
a24007a
Merge branch 'main' into noahdarveau/custom-eslint-plugin
AE-MS Apr 19, 2024
3467499
Merge branch 'main' into noahdarveau/custom-eslint-plugin
noahdarveau-MSFT Apr 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/teams-js/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = {
parserOptions: {
project: './tsconfig.eslint.json',
},
plugins: ['strict-null-checks'],
plugins: ['strict-null-checks', 'recommend-const-enums'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/no-namespace': 'off',
Expand All @@ -13,5 +13,6 @@ module.exports = {
],
'no-inner-declarations': 'off',
'strict-null-checks/all': 'warn',
'recommend-const-enums/recommend-const-enums': 'warn',
},
};
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;
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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noah

lol

"description": "Recommend using const enums",
"type": "commonjs",
"keywords": [
"eslint",
"eslint-plugin",
"eslintplugin"
],
"peerDependencies": {
"eslint": ">=5.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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.`,
noahdarveau-MSFT marked this conversation as resolved.
Show resolved Hide resolved
noahdarveau-MSFT marked this conversation as resolved.
Show resolved Hide resolved
severity: 2,
//fix(fixer) {
// return fixer.insertTextBefore(node, 'const ');
//},
});
}
},
};
},
};
3 changes: 2 additions & 1 deletion packages/teams-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"debug": "^4.3.3"
},
"devDependencies": {
"@types/debug": "^4.1.7"
"@types/debug": "^4.1.7",
"eslint-plugin-recommend-const-enums": "file:./eslint-rules/eslint-plugin-recommend-const-enums"
},
"license": "MIT",
"files": [
Expand Down
1 change: 1 addition & 0 deletions packages/teams-js/src/private/remoteCamera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export namespace remoteCamera {
* @internal
* Limited to Microsoft-internal use
*/
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
noahdarveau-MSFT marked this conversation as resolved.
Show resolved Hide resolved
export enum ControlCommand {
Reset = 'Reset',
ZoomIn = 'ZoomIn',
Expand Down
4 changes: 4 additions & 0 deletions packages/teams-js/src/public/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export namespace app {
/**
* Describes errors that caused app initialization to fail
*/
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export enum FailedReason {
/**
* Authentication failed
Expand All @@ -246,6 +247,7 @@ export namespace app {
* Describes expected errors that occurred during an otherwise successful
* app initialization
*/
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export enum ExpectedFailureReason {
/**
* There was a permission error
Expand All @@ -272,6 +274,7 @@ export namespace app {
/**
* Represents the failed request sent during a failed app initialization.
*/
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export interface IFailedRequest {
/**
* The reason for the failure
Expand All @@ -286,6 +289,7 @@ export namespace app {
/**
* Represents the failure request sent during an erroneous app initialization.
*/
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export interface IExpectedFailureRequest {
/**
* The reason for the failure
Expand Down
4 changes: 4 additions & 0 deletions packages/teams-js/src/public/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/** HostClientType represents the different client platforms on which host can be run. */
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export enum HostClientType {
/** Represents the desktop client of host, which is installed on a user's computer and runs as a standalone application. */
desktop = 'desktop',
Expand Down Expand Up @@ -78,6 +79,7 @@ export const enum HostName {
* If the app is running in the content context, the developer may want to display information relevant to
* the content the user is currently viewing.
*/
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export enum FrameContexts {
/**
* App's frame context from where settings page can be accessed.
Expand All @@ -104,6 +106,7 @@ export enum FrameContexts {
* Indicates the team type, currently used to distinguish between different team
* types in Office 365 for Education (team types 1, 2, 3, and 4).
*/
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export enum TeamType {
/** Represents a standard or classic team in host that is designed for ongoing collaboration and communication among a group of people. */
Standard = 0,
Expand All @@ -120,6 +123,7 @@ export enum TeamType {
/**
* Indicates the various types of roles of a user in a team.
*/
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export enum UserTeamRole {
/** Represents that the user is an owner or administrator of the team. */
Admin = 0,
Expand Down
2 changes: 2 additions & 0 deletions packages/teams-js/src/public/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,7 @@ export function isSdkError(err: unknown): err is SdkError {
}

/** Error codes used to identify different types of errors that can occur while developing apps. */
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export enum ErrorCode {
/**
* API not supported in the current platform.
Expand Down Expand Up @@ -1077,6 +1078,7 @@ export interface AdaptiveCardVersion {
/**
* Currently supported Mime type
*/
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export enum ClipboardSupportedMimeType {
TextPlain = 'text/plain',
TextHtml = 'text/html',
Expand Down
1 change: 1 addition & 0 deletions packages/teams-js/src/public/mail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export namespace mail {
}

/** Defines compose mail types. */
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export enum ComposeMailType {
/** Compose a new mail message. */
New = 'new',
Expand Down
1 change: 1 addition & 0 deletions packages/teams-js/src/public/marketplace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ export namespace marketplace {
* Represents the status of the cart.
* @beta
*/
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export enum CartStatus {
/**
* @hidden
Expand Down
6 changes: 6 additions & 0 deletions packages/teams-js/src/public/media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ export namespace media {
* @beta
* Events which are used to communicate between the app and the host client during the media recording flow
*/
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export enum MediaControllerEvent {
/** Start recording. */
StartRecording = 1,
Expand Down Expand Up @@ -638,6 +639,7 @@ export namespace media {
/**
* The modes in which camera can be launched in select Media API
*/
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export enum CameraStartMode {
/** Photo mode. */
Photo = 1,
Expand All @@ -652,6 +654,7 @@ export namespace media {
/**
* Specifies the image source
*/
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export enum Source {
/** Image source is camera. */
Camera = 1,
Expand All @@ -662,6 +665,7 @@ export namespace media {
/**
* Specifies the type of Media
*/
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export enum MediaType {
/** Media type photo or image */
Image = 1,
Expand All @@ -686,6 +690,7 @@ export namespace media {
/**
* ID contains a mapping for content uri on platform's side, URL is generic
*/
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export enum ImageUriType {
/** Image Id. */
ID = 1,
Expand All @@ -696,6 +701,7 @@ export namespace media {
/**
* Specifies the image output formats.
*/
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export enum ImageOutputFormats {
/** Outputs image. */
IMAGE = 1,
Expand Down
1 change: 1 addition & 0 deletions packages/teams-js/src/public/meeting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ export namespace meeting {
/**
* Reasons for the app's microphone state to change
*/
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
enum MicStateChangeReason {
HostInitiated,
AppInitiated,
Expand Down
1 change: 1 addition & 0 deletions packages/teams-js/src/public/menus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export namespace menus {
/**
* Defines how a menu item should appear in the NavBar.
*/
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export enum DisplayMode {
/**
* Only place this item in the NavBar if there's room for it.
Expand Down
1 change: 1 addition & 0 deletions packages/teams-js/src/public/videoEffects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export namespace videoEffects {
* Predefined failure reasons for preparing the selected video effect
* @beta
*/
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export enum EffectFailureReason {
/**
* A wrong effect id is provide.
Expand Down
2 changes: 2 additions & 0 deletions packages/teams-js/src/public/visualMedia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export namespace visualMedia {
*
* @beta
*/
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export enum CameraRestriction {
/** User can move between front and back camera */
FrontOrRear = 1,
Expand All @@ -85,6 +86,7 @@ export namespace visualMedia {
*
* @beta
*/
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export enum Source {
/** The camera is the source of visual media. */
Camera = 1,
Expand Down
1 change: 1 addition & 0 deletions packages/teams-js/test/promiseTester.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
noahdarveau-MSFT marked this conversation as resolved.
Show resolved Hide resolved
export enum PromiseState {
Pending = 'pending',
Resolved = 'resolved',
Expand Down
1 change: 1 addition & 0 deletions packages/teams-js/test/public/runtime.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ describe('runtime', () => {
return `${version}.1`;
}

/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
noahdarveau-MSFT marked this conversation as resolved.
Show resolved Hide resolved
enum OlderOrNewerVersions {
OlderVersions,
NewerVersions,
Expand Down
1 change: 1 addition & 0 deletions packages/teams-js/test/resultValidation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { MessageRequest } from './utils';

/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
noahdarveau-MSFT marked this conversation as resolved.
Show resolved Hide resolved
export enum MatcherType {
ToBe,
ToStrictEqual,
Expand Down