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 7 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 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
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"
}
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,29 @@
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,
});
}
},
};
},
};
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
1 change: 1 addition & 0 deletions packages/teams-js/src/public/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,7 @@ export namespace authentication {
* @internal
* Limited to Microsoft-internal use
*/
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export enum DataResidency {
/**
* Public
Expand Down
1 change: 1 addition & 0 deletions packages/teams-js/src/public/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const callTelemetryVersionNumber: ApiVersionNumber = ApiVersionNumber.V_2;
*/
export namespace call {
/** Modalities that can be associated with a call. */
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export enum CallModalities {
/** Indicates that the modality is unknown or undefined. */
Unknown = 'unknown',
Expand Down
7 changes: 7 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 @@ -30,6 +31,7 @@ export enum HostClientType {
}

/** HostName indicates the possible hosts for your application. */
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export enum HostName {
/**
* Office.com and Office Windows App
Expand Down Expand Up @@ -78,6 +80,7 @@ export 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 +107,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 +124,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 All @@ -132,6 +137,7 @@ export enum UserTeamRole {
/**
* Dialog module dimension enum
*/
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export enum DialogDimension {
/** Represents a large-sized dialog box, which is typically used for displaying large amounts of content or complex workflows that require more space. */
Large = 'large',
Expand All @@ -153,6 +159,7 @@ import { HostVersionsInfo } from './interfaces';
/**
* The type of the channel with which the content is associated.
*/
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export enum ChannelType {
/** The default channel type. Type of channel is used for general collaboration and communication within a team. */
Regular = 'Regular',
Expand Down
6 changes: 6 additions & 0 deletions packages/teams-js/src/public/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ export interface LocaleInfo {
/**
* Allowed user file open preferences
*/
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export enum FileOpenPreference {
/** Indicates that the user should be prompted to open the file in inline. */
Inline = 'inline',
Expand All @@ -200,6 +201,7 @@ export enum FileOpenPreference {
*
* @beta
*/
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export enum ActionObjectType {
/** Represents content within a Microsoft 365 application. */
M365Content = 'm365content',
Expand Down Expand Up @@ -250,6 +252,7 @@ export interface SecondaryId {
* See [commonly accessed resources](https://learn.microsoft.com/graph/api/resources/onedrive?view=graph-rest-1.0#commonly-accessed-resources).
* @beta
*/
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export enum SecondaryM365ContentIdName {
/** OneDrive ID */
DriveId = 'driveId',
Expand Down Expand Up @@ -990,6 +993,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 @@ -1054,6 +1058,7 @@ export enum ErrorCode {
}

/** @hidden */
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export enum DevicePermission {
GeoLocation = 'geolocation',
Media = 'media',
Expand All @@ -1077,6 +1082,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
2 changes: 2 additions & 0 deletions packages/teams-js/src/public/liveShareHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export namespace liveShare {
* Used in Live Share for its role verification feature.
* For more information, visit https://learn.microsoft.com/microsoftteams/platform/apps-in-teams-meetings/teams-live-share-capabilities?tabs=javascript#role-verification-for-live-data-structures
*/
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export enum UserMeetingRole {
/**
* Guest role.
Expand All @@ -46,6 +47,7 @@ export namespace liveShare {
* State of the current Live Share session's Fluid container.
* This is used internally by the `LiveShareClient` when joining a Live Share session.
*/
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export enum ContainerState {
/**
* The call to `LiveShareHost.setContainerId()` successfully created the container mapping
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
2 changes: 2 additions & 0 deletions packages/teams-js/src/public/marketplace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ export namespace marketplace {
* Represents the persona creating the cart.
* @beta
*/
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export enum Intent {
/**
* @hidden
Expand All @@ -226,6 +227,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
7 changes: 7 additions & 0 deletions packages/teams-js/src/public/media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export namespace media {
/**
* Enum for file formats supported
*/
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export enum FileFormat {
/** Base64 encoding */
Base64 = 'base64',
Expand Down Expand Up @@ -610,6 +611,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 +640,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 +655,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 +666,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 +691,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 +702,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
6 changes: 6 additions & 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 Expand Up @@ -409,6 +410,7 @@ export namespace meeting {
*
* @beta
*/
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export enum MeetingReactionType {
like = 'like',
heart = 'heart',
Expand All @@ -426,6 +428,7 @@ export namespace meeting {
* @remarks
* Teams has several types of meetings to account for different user scenarios and requirements.
*/
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export enum MeetingType {
/**
* Used when the meeting type is not known.
Expand Down Expand Up @@ -481,6 +484,7 @@ export namespace meeting {
* @hidden
* Hide from docs.
*/
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export enum CallType {
/**
* Represents a call between two people.
Expand All @@ -502,6 +506,7 @@ export namespace meeting {
/**
* Represents the protocol option for sharing app content to the meeting stage.
*/
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export enum SharingProtocol {
/**
* The default protocol for sharing app content to stage. To learn more, visit https://aka.ms/teamsjs/shareAppContentToStage
Expand Down Expand Up @@ -977,6 +982,7 @@ export namespace meeting {
}

/** The source of the join button click. */
/* eslint-disable-next-line recommend-const-enums/recommend-const-enums */
export enum EventActionSource {
/**
* Source is calendar grid context menu.
Expand Down