From 8301977e3dec1ee9ce54d61ccf779e6ed8cbf839 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Thu, 21 Mar 2024 09:39:47 -0700 Subject: [PATCH 1/4] enable no-enum rule --- packages/typespec-azure-core/src/linter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/typespec-azure-core/src/linter.ts b/packages/typespec-azure-core/src/linter.ts index e93fe4fe7e..898b4a2579 100644 --- a/packages/typespec-azure-core/src/linter.ts +++ b/packages/typespec-azure-core/src/linter.ts @@ -110,7 +110,7 @@ export const $linter = defineLinter({ true, [`@azure-tools/typespec-azure-core/${useStandardNames.name}`]: true, [`@azure-tools/typespec-azure-core/${friendlyNameRule.name}`]: true, - [`@azure-tools/typespec-azure-core/${noEnumRule.name}`]: false, + [`@azure-tools/typespec-azure-core/${noEnumRule.name}`]: true, }, extends: ["@typespec/http/all"], }, From 85fb7f31d4c67bb5abd215c73c70e03e295deb5d Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Thu, 21 Mar 2024 10:15:01 -0700 Subject: [PATCH 2/4] Create enable-no-enum-rule-2024-2-21-16-42-36.md --- .../changes/enable-no-enum-rule-2024-2-21-16-42-36.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .chronus/changes/enable-no-enum-rule-2024-2-21-16-42-36.md diff --git a/.chronus/changes/enable-no-enum-rule-2024-2-21-16-42-36.md b/.chronus/changes/enable-no-enum-rule-2024-2-21-16-42-36.md new file mode 100644 index 0000000000..775f599b17 --- /dev/null +++ b/.chronus/changes/enable-no-enum-rule-2024-2-21-16-42-36.md @@ -0,0 +1,8 @@ +--- +# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking +changeKind: fix +packages: + - "@azure-tools/typespec-azure-core" +--- + +Enable `no-enum` rule by default in `all` ruleset From 78b66c9ab62561e3b10587db2ccf2f66a60502e6 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Thu, 21 Mar 2024 13:32:42 -0700 Subject: [PATCH 3/4] fix rule --- .../typespec-azure-core/src/rules/no-enum.ts | 4 +++- .../test/rules/no-enum.test.ts | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/packages/typespec-azure-core/src/rules/no-enum.ts b/packages/typespec-azure-core/src/rules/no-enum.ts index 6c04206d00..ab7f5288f5 100644 --- a/packages/typespec-azure-core/src/rules/no-enum.ts +++ b/packages/typespec-azure-core/src/rules/no-enum.ts @@ -23,9 +23,11 @@ export const noEnumRule = createRule({ create(context) { return { enum: (en: Enum) => { - if (getVersionsForEnum(context.program, en).length > 0) { + const [_, versions] = getVersionsForEnum(context.program, en); + if (versions !== undefined && versions.getVersions()[0].enumMember.enum === en) { return; } + context.reportDiagnostic({ format: { enumName: en.name }, target: en, diff --git a/packages/typespec-azure-core/test/rules/no-enum.test.ts b/packages/typespec-azure-core/test/rules/no-enum.test.ts index 784a630fc7..9913e609d7 100644 --- a/packages/typespec-azure-core/test/rules/no-enum.test.ts +++ b/packages/typespec-azure-core/test/rules/no-enum.test.ts @@ -31,6 +31,7 @@ describe("typespec-azure-core: no-enum rule", () => { }, ]); }); + it("allows the version enum", async () => { await tester .expect( @@ -46,6 +47,27 @@ describe("typespec-azure-core: no-enum rule", () => { .toBeValid(); }); + it("emit warning about other enums in versioned service", async () => { + await tester + .expect( + ` + @service + @versioned(Versions) + namespace Foo; + enum Versions { + v1, v2 + } + + enum Bar { a, b} + ` + ) + .toEmitDiagnostics([ + { + code: "@azure-tools/typespec-azure-core/no-enum", + }, + ]); + }); + describe("codefix", () => { it("codefix simple enum", async () => { await tester From 35d146775348ac238026dd47270aec38e2049a19 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Thu, 21 Mar 2024 13:33:55 -0700 Subject: [PATCH 4/4] Update .chronus/changes/enable-no-enum-rule-2024-2-21-16-42-36.md --- .chronus/changes/enable-no-enum-rule-2024-2-21-16-42-36.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chronus/changes/enable-no-enum-rule-2024-2-21-16-42-36.md b/.chronus/changes/enable-no-enum-rule-2024-2-21-16-42-36.md index 775f599b17..3768d3d751 100644 --- a/.chronus/changes/enable-no-enum-rule-2024-2-21-16-42-36.md +++ b/.chronus/changes/enable-no-enum-rule-2024-2-21-16-42-36.md @@ -1,6 +1,6 @@ --- # Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking -changeKind: fix +changeKind: feature packages: - "@azure-tools/typespec-azure-core" ---