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
2 changes: 1 addition & 1 deletion src/cdk/platform/features/scrolling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

/** The possible ways the browser may handle the horizontal scroll axis in RTL languages. */
export enum RtlScrollAxisType {
export const enum RtlScrollAxisType {
/**
* scrollLeft is 0 when scrolled all the way left and (scrollWidth - clientWidth) when scrolled
* all the way right.
Expand Down
2 changes: 2 additions & 0 deletions src/cdk/schematics/update-tool/target-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*/

/** Possible versions that can be automatically migrated by `ng update`. */
// Used in an `Object.keys` call below so it can't be `const enum`.
// tslint:disable-next-line:prefer-const-enum
export enum TargetVersion {
V6 = 'version 6',
V7 = 'version 7',
Expand Down
1 change: 1 addition & 0 deletions src/cdk/testing/test-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface ModifierKeys {
// dependency on any particular testing framework here. Instead we'll just maintain this supported
// list of keys and let individual concrete `HarnessEnvironment` classes map them to whatever key
// representation is used in its respective testing framework.
// tslint:disable-next-line:prefer-const-enum Seems like this causes some issues with System.js
export enum TestKey {
BACKSPACE,
TAB,
Expand Down
2 changes: 1 addition & 1 deletion src/material/checkbox/checkbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const MAT_CHECKBOX_CONTROL_VALUE_ACCESSOR: any = {
* Represents the different states that require custom transitions between them.
* @docs-private
*/
export enum TransitionCheckState {
export const enum TransitionCheckState {
/** The initial state of the component before any user interaction. */
Init,
/** The state representing the component when it's becoming checked. */
Expand Down
2 changes: 1 addition & 1 deletion src/material/core/ripple/ripple-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import {RippleConfig, RippleRenderer} from './ripple-renderer';

/** Possible states for a ripple element. */
export enum RippleState {
export const enum RippleState {
FADING_IN, VISIBLE, FADING_OUT, HIDDEN
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import * as ts from 'typescript';
// tslint:disable:no-bitwise

/** Enum describing the possible states of an analyzed import. */
enum ImportState {
const enum ImportState {
UNMODIFIED = 0b0,
MODIFIED = 0b10,
ADDED = 0b100,
Expand Down
2 changes: 1 addition & 1 deletion tools/public_api_guard/cdk/platform.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export declare class PlatformModule {
static ɵmod: i0.ɵɵNgModuleDefWithMeta<PlatformModule, never, never, never>;
}

export declare enum RtlScrollAxisType {
export declare const enum RtlScrollAxisType {
NORMAL = 0,
NEGATED = 1,
INVERTED = 2
Expand Down
2 changes: 1 addition & 1 deletion tools/public_api_guard/material/checkbox.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export declare class MatCheckboxRequiredValidator extends CheckboxRequiredValida
static ɵfac: i0.ɵɵFactoryDef<MatCheckboxRequiredValidator>;
}

export declare enum TransitionCheckState {
export declare const enum TransitionCheckState {
Init = 0,
Checked = 1,
Unchecked = 2,
Expand Down
2 changes: 1 addition & 1 deletion tools/public_api_guard/material/core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ export declare class RippleRenderer {
setupTriggerEvents(elementOrElementRef: HTMLElement | ElementRef<HTMLElement>): void;
}

export declare enum RippleState {
export declare const enum RippleState {
FADING_IN = 0,
VISIBLE = 1,
FADING_OUT = 2,
Expand Down
22 changes: 22 additions & 0 deletions tools/tslint-rules/preferConstEnumRule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as ts from 'typescript';
import * as Lint from 'tslint';
import * as tsutils from 'tsutils';

/**
* Rule that enforces that we use `const enum` rather than a plain `enum`.
*/
export class Rule extends Lint.Rules.AbstractRule {
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
return this.applyWithWalker(new Walker(sourceFile, this.getOptions()));
}
}

class Walker extends Lint.RuleWalker {
visitEnumDeclaration(node: ts.EnumDeclaration) {
if (!tsutils.hasModifier(node.modifiers, ts.SyntaxKind.ConstKeyword)) {
this.addFailureAtNode(node.name, 'Enums should be declared as `const enum`.');
}

super.visitEnumDeclaration(node);
}
}
1 change: 1 addition & 0 deletions tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
"require-breaking-change-version": true,
"class-list-signatures": true,
"no-nested-ternary": true,
"prefer-const-enum": true,
"coercion-types": [true,
["coerceBooleanProperty", "coerceCssPixelValue", "coerceNumberProperty"],
{
Expand Down