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

Adapt New Rules To Old Rules #32297

Closed
wants to merge 105 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
6bb00d3
WIP: Implement TSV as ESLint Rules
mikeharder Dec 17, 2024
2b9965f
Convert to TS (but still cjs)
mikeharder Dec 17, 2024
1ae2452
Convert to mjs
mikeharder Dec 17, 2024
57655ba
Add contoso test
mikeharder Dec 17, 2024
0615363
Add rule top-level-folder-lowercase
mikeharder Dec 17, 2024
6e44905
build before test
mikeharder Dec 17, 2024
ae8a8a5
Rename rule to align with eslint conventions
mikeharder Dec 17, 2024
79256c4
Rename rule
mikeharder Dec 17, 2024
85db158
Improve test
mikeharder Dec 17, 2024
4973878
Remove sample rule
mikeharder Dec 17, 2024
89006ec
Move e2e tests to separate folder
mikeharder Dec 17, 2024
0fe7173
Add comment
mikeharder Dec 17, 2024
da8c9aa
Add manual unit test
mikeharder Dec 17, 2024
abf58cc
Convert test to vitest
mikeharder Dec 17, 2024
043d24e
Remove unnecessary async
mikeharder Dec 17, 2024
6184c64
Rename rule and improve error message
mikeharder Dec 18, 2024
b03b666
Test eslint disablement comment
mikeharder Dec 18, 2024
9c09894
Add tests for disabled rule
mikeharder Dec 18, 2024
a0d0fef
Include recommended config
mikeharder Dec 18, 2024
0de1b3e
Move rules to subfolder
mikeharder Dec 18, 2024
2208b20
Cleanup ts-ignore
mikeharder Dec 18, 2024
5b3571f
Remove comment
mikeharder Dec 18, 2024
cc6d19c
WIP: Add Npm.prefix() helper method and tests
mikeharder Dec 18, 2024
659ed1e
Use memfs to test fs code
mikeharder Dec 18, 2024
a097482
Add failing tests
mikeharder Dec 19, 2024
1afea81
Implement prefix()
mikeharder Dec 19, 2024
67ddba4
Add more bulk test commands
mikeharder Dec 19, 2024
0c239f5
Add test workflow
mikeharder Dec 19, 2024
6903a12
Downgrade rimraf to v5 for node18 compat
mikeharder Dec 19, 2024
8978c86
Add code coverage
mikeharder Dec 19, 2024
83d874c
Normalize paths so tests pass on win32
mikeharder Dec 19, 2024
786140b
normalize expected value
mikeharder Dec 19, 2024
40c0796
Rename job
mikeharder Dec 19, 2024
908df37
Add comment
mikeharder Dec 19, 2024
5fe0a1f
Always return absolute path
mikeharder Dec 19, 2024
3009311
Resolve path before splitting
mikeharder Dec 19, 2024
d130711
Merge branch 'main' into eslint-plugin-tsv
mikeharder Dec 19, 2024
a92698f
Add stub for e2e vite tests
mikeharder Dec 19, 2024
3e93efa
Remove comment
mikeharder Dec 19, 2024
41814f9
Add ESLint with names
mikeharder Dec 19, 2024
5907a21
Add dummy test to prevent errors
mikeharder Dec 19, 2024
d0ae1de
Stronger config typing
mikeharder Dec 19, 2024
49d09b6
Move e2e test
mikeharder Dec 19, 2024
2563cd2
Run tests when contoso changes
mikeharder Dec 20, 2024
6a555fb
Add e2e test using real filesystem
mikeharder Dec 20, 2024
dd472f8
Remove old test
mikeharder Dec 20, 2024
d7439da
Improve test name
mikeharder Dec 20, 2024
90fab86
Fix e2e tests
mikeharder Dec 20, 2024
9f5ad9b
Exclude interface from coverage
mikeharder Dec 20, 2024
fac51d7
Exclude interfaces from coverage
mikeharder Dec 20, 2024
313f926
Add Management e2e test
mikeharder Dec 20, 2024
5cb8558
improve error validation
mikeharder Dec 20, 2024
29c9f1f
Handle invalid path errors
mikeharder Dec 20, 2024
b02de1e
Merge branch 'main' into eslint-plugin-tsv
mikeharder Dec 20, 2024
81f2cc8
Remove e2e scripts
mikeharder Dec 20, 2024
3a0425a
Merge branch 'main' into eslint-plugin-tsv
mikeharder Dec 21, 2024
c7493c1
Remove problematic vitest config
mikeharder Dec 21, 2024
adbc241
Revert "Remove problematic vitest config"
mikeharder Dec 24, 2024
61fe81b
Exclude vitest config from compilation
mikeharder Dec 24, 2024
cb8d4f5
Merge branch 'main' into eslint-plugin-tsv
mikeharder Jan 6, 2025
28a6aff
[tsconfig.json] Replace excludes with includes
mikeharder Jan 6, 2025
733db68
Add comment
mikeharder Jan 7, 2025
3b7580e
Add stub for new rule emit-autorest
mikeharder Jan 7, 2025
f5d864f
Validate tspconfig.yaml, ensure default emitter
mikeharder Jan 7, 2025
bcc439e
Merge branch 'main' into eslint-plugin-tsv
mikeharder Jan 8, 2025
6b5ebdb
add first test
wanlwanl Jan 21, 2025
4c41980
simplify for adding new rules
wanlwanl Jan 21, 2025
b1ae1a3
all js rules added
wanlwanl Jan 21, 2025
40c65f0
added go rules
wanlwanl Jan 21, 2025
887282b
added all rules! : )
wanlwanl Jan 22, 2025
3c767cf
update rule setup
wanlwanl Jan 23, 2025
b7a9cc8
Merge branch 'wanl/add-tsp-config-rule' into wanl/adapt-new-rules-to-…
wanlwanl Jan 23, 2025
68aa395
remove workflow
wanlwanl Jan 23, 2025
cac0504
remove an unused file
wanlwanl Jan 23, 2025
b8dc93e
Merge branch 'wanl/add-tsp-config-rule' into wanl/adapt-new-rules-to-…
wanlwanl Jan 23, 2025
a0dbd75
converting
wanlwanl Jan 23, 2025
e7dd065
WIP
wanlwanl Jan 23, 2025
91c2f28
fix doc
wanlwanl Jan 23, 2025
93ed768
Merge branch 'wanl/add-tsp-config-rule' into wanl/adapt-new-rules-to-…
wanlwanl Jan 23, 2025
06003ea
WIP
wanlwanl Jan 23, 2025
81508d0
fix
wanlwanl Jan 23, 2025
740c3c5
Merge branch 'wanl/add-tsp-config-rule' into wanl/adapt-new-rules-to-…
wanlwanl Jan 23, 2025
73a8562
add simple test
wanlwanl Jan 24, 2025
f84257b
update java rule
wanlwanl Jan 24, 2025
00ecf30
Merge branch 'wanl/add-tsp-config-rule' into wanl/adapt-new-rules-to-…
wanlwanl Jan 24, 2025
4d2c8f3
update test
wanlwanl Jan 24, 2025
db989a6
add new rules
wanlwanl Jan 24, 2025
2ba3d59
remove files
wanlwanl Jan 24, 2025
9f84497
fix lint error
wanlwanl Jan 24, 2025
de66d5d
Merge branch 'wanl/add-tsp-config-rule' into wanl/adapt-new-rules-to-…
wanlwanl Jan 24, 2025
4d1359c
update lock file
wanlwanl Jan 24, 2025
4e7e4ee
delete flavor rule
wanlwanl Jan 24, 2025
9a5ce80
Merge branch 'wanl/add-tsp-config-rule' into wanl/adapt-new-rules-to-…
wanlwanl Jan 24, 2025
fa6c65a
update tsconfig
wanlwanl Jan 24, 2025
593970c
fix
wanlwanl Jan 24, 2025
8550e88
update
wanlwanl Jan 24, 2025
71fec2e
improve placeholder
wanlwanl Jan 24, 2025
e346642
Merge branch 'wanl/add-tsp-config-rule' into wanl/adapt-new-rules-to-…
wanlwanl Jan 24, 2025
9a378a0
improve message
wanlwanl Jan 24, 2025
725770b
Merge branch 'wanl/add-tsp-config-rule' into wanl/adapt-new-rules-to-…
wanlwanl Jan 24, 2025
01ec98c
update
wanlwanl Jan 24, 2025
d770c0d
improve message
wanlwanl Jan 24, 2025
5158a33
remove new tool and put new code into current TSV
wanlwanl Jan 26, 2025
718cb30
revert tsconfig
wanlwanl Jan 26, 2025
06435c3
removed unnecessary rules
wanlwanl Jan 26, 2025
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
7 changes: 5 additions & 2 deletions eng/tools/typespec-validation/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{

Check failure on line 1 in eng/tools/typespec-validation/package.json

View workflow job for this annotation

GitHub Actions / Protected Files

File 'eng/tools/typespec-validation/package.json' should only be updated by the Azure SDK team. If intentional, the PR may be merged by the Azure SDK team via bypassing the branch protections.
"name": "@azure-tools/typespec-validation",
"private": true,
"type": "module",
Expand All @@ -10,13 +10,16 @@
"globby": "^14.0.1",
"simple-git": "^3.24.0",
"suppressions": "file:../suppressions",
"yaml": "^2.4.2"
"yaml": "^2.4.2",
"ajv": "^8.17.1",
"yaml-eslint-parser": "^1.2.3"
},
"devDependencies": {
"@types/node": "^18.19.31",
"@vitest/coverage-v8": "^3.0.2",
"typescript": "~5.6.2",
"vitest": "^3.0.2"
"vitest": "^3.0.2",
"eslint": "^9.17.0"
},
"scripts": {
"build": "tsc --build",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// Copied from https://github.com/microsoft/typespec/blob/main/packages/compiler/src/config/config-schema.ts

Check failure on line 1 in eng/tools/typespec-validation/src/eslint-plugin-tsv/src/config/config-schema.ts

View workflow job for this annotation

GitHub Actions / Protected Files

File 'eng/tools/typespec-validation/src/eslint-plugin-tsv/src/config/config-schema.ts' should only be updated by the Azure SDK team. If intentional, the PR may be merged by the Azure SDK team via bypassing the branch protections.

import type { JSONSchemaType } from "ajv";
import { EmitterOptions, TypeSpecRawConfig } from "./types.js";

export const emitterOptionsSchema: JSONSchemaType<EmitterOptions> = {
type: "object",
additionalProperties: true,
required: [],
properties: {
"emitter-output-dir": { type: "string", nullable: true } as any,
},
};

export const TypeSpecConfigJsonSchema: JSONSchemaType<TypeSpecRawConfig> = {
type: "object",
additionalProperties: false,
properties: {
extends: {
type: "string",
nullable: true,
},
"environment-variables": {
type: "object",
nullable: true,
required: [],
additionalProperties: {
type: "object",
properties: {
default: { type: "string" },
},
required: ["default"],
},
},
parameters: {
type: "object",
nullable: true,
required: [],
additionalProperties: {
type: "object",
properties: {
default: { type: "string" },
},
required: ["default"],
},
},

"output-dir": {
type: "string",
nullable: true,
},
"warn-as-error": {
type: "boolean",
nullable: true,
},
trace: {
oneOf: [
{ type: "string" },
{
type: "array",
items: { type: "string" },
},
],
} as any, // Issue with AJV optional property typing https://github.com/ajv-validator/ajv/issues/1664
imports: {
type: "array",
nullable: true,
items: { type: "string" },
},
emit: {
type: "array",
nullable: true,
items: { type: "string" },
},
options: {
type: "object",
nullable: true,
required: [],
additionalProperties: emitterOptionsSchema,
},
emitters: {
type: "object",
nullable: true,
deprecated: true,
required: [],
additionalProperties: {
oneOf: [{ type: "boolean" }, emitterOptionsSchema],
},
},

linter: {
type: "object",
nullable: true,
required: [],
additionalProperties: false,
properties: {
extends: {
type: "array",
nullable: true,
items: { type: "string" },
},
enable: {
type: "object",
required: [],
nullable: true,
additionalProperties: { type: "boolean" },
},
disable: {
type: "object",
required: [],
nullable: true,
additionalProperties: { type: "string" },
},
},
} as any, // ajv type system doesn't like the string templates
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// Copied from https://github.com/microsoft/typespec/blob/main/packages/compiler/src/config/types.ts

Check failure on line 1 in eng/tools/typespec-validation/src/eslint-plugin-tsv/src/config/types.ts

View workflow job for this annotation

GitHub Actions / Protected Files

File 'eng/tools/typespec-validation/src/eslint-plugin-tsv/src/config/types.ts' should only be updated by the Azure SDK team. If intentional, the PR may be merged by the Azure SDK team via bypassing the branch protections.

import type { Diagnostic, RuleRef } from "@typespec/compiler";
import type { YamlScript } from "../yaml/types.js";

/**
* Represent the normalized user configuration.
*/
export interface TypeSpecConfig {
/**
* Project root.
*/
projectRoot: string;

/** Yaml file used in this configuration. */
file?: YamlScript;

/**
* Path to the config file used to create this configuration.
*/
filename?: string;

/**
* Diagnostics reported while loading the configuration
*/
diagnostics: Diagnostic[];

/**
* Path to another TypeSpec config to extend.
*/
extends?: string;

/**
* Environment variables configuration
*/
environmentVariables?: Record<string, ConfigEnvironmentVariable>;

/**
* Parameters that can be used
*/
parameters?: Record<string, ConfigParameter>;

/**
* Treat warning as error.
*/
warnAsError?: boolean;

/**
* Output directory
*/
outputDir: string;

/**
* Trace options.
*/
trace?: string[];

/**
* Additional imports.
*/
imports?: string[];

/**
* Name of emitters or path to emitters that should be used.
*/
emit?: string[];

/**
* Name of emitters or path to emitters that should be used.
*/
options?: Record<string, EmitterOptions>;

linter?: LinterConfig;
}

/**
* Represent the configuration that can be provided in a config file.
*/
export interface TypeSpecRawConfig {
extends?: string;
"environment-variables"?: Record<string, ConfigEnvironmentVariable>;
parameters?: Record<string, ConfigParameter>;

"warn-as-error"?: boolean;
"output-dir"?: string;
trace?: string | string[];
imports?: string[];

emit?: string[];
options?: Record<string, EmitterOptions>;
emitters?: Record<string, boolean | EmitterOptions>;

linter?: LinterConfig;
}

export interface ConfigEnvironmentVariable {
default: string;
}

export interface ConfigParameter {
default: string;
}

export type EmitterOptions = Record<string, unknown> & {
"emitter-output-dir"?: string;
};

export interface LinterConfig {
extends?: RuleRef[];
enable?: Record<RuleRef, boolean>;
disable?: Record<RuleRef, string>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import parser from "yaml-eslint-parser";

Check failure on line 1 in eng/tools/typespec-validation/src/eslint-plugin-tsv/src/eslint-plugin-tsv.ts

View workflow job for this annotation

GitHub Actions / Protected Files

File 'eng/tools/typespec-validation/src/eslint-plugin-tsv/src/eslint-plugin-tsv.ts' should only be updated by the Azure SDK team. If intentional, the PR may be merged by the Azure SDK team via bypassing the branch protections.
import { NamedESLint } from "./interfaces/named-eslint.js";
import tspconfigValidationRules from "./rules/tspconfig-validation-rules.js";

const plugin: NamedESLint.Plugin = {
configs: { recommended: {} },
name: "tsv",
rules: {},
};

plugin.configs.recommended = {
plugins: {
[plugin.name]: plugin,
},
files: ["*.yaml", "**/*.yaml"],
rules: {},
languageOptions: {
parser: parser,
},
};

tspconfigValidationRules.forEach((rule) => {
plugin.rules![rule.name] = rule;
plugin.configs.recommended.rules![`${plugin.name}/${rule.name}`] = "error";
});

export default plugin;
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ESLint, Linter, Rule } from "eslint";

Check failure on line 1 in eng/tools/typespec-validation/src/eslint-plugin-tsv/src/interfaces/named-eslint.ts

View workflow job for this annotation

GitHub Actions / Protected Files

File 'eng/tools/typespec-validation/src/eslint-plugin-tsv/src/interfaces/named-eslint.ts' should only be updated by the Azure SDK team. If intentional, the PR may be merged by the Azure SDK team via bypassing the branch protections.

// ESLint with names for convenience

export namespace NamedRule {
export interface RuleModule extends Rule.RuleModule {
name: string;
}
}

export namespace NamedESLint {
export interface Plugin extends ESLint.Plugin {
configs: { recommended: Linter.Config };
name: string;
rules?: Record<string, NamedRule.RuleModule>;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Rule } from "eslint";

Check failure on line 1 in eng/tools/typespec-validation/src/eslint-plugin-tsv/src/interfaces/rule-interfaces.ts

View workflow job for this annotation

GitHub Actions / Protected Files

File 'eng/tools/typespec-validation/src/eslint-plugin-tsv/src/interfaces/rule-interfaces.ts' should only be updated by the Azure SDK team. If intentional, the PR may be merged by the Azure SDK team via bypassing the branch protections.
import { TypeSpecConfig } from "../config/types.js";

export enum KeyType {
EmitterOption,
Parameter,
}

export interface RuleDocument {
description: string;
error: string;
action: string;
example: string;
}

export interface RuleInfo {
name: string;
documentation: RuleDocument;
functions: {
messages: () => { [messageId: string]: string } | undefined;
condition: (tspconfig: TypeSpecConfig, context: Rule.RuleContext) => boolean;
validation: (tspconfig: TypeSpecConfig, context: Rule.RuleContext, node: Rule.Node) => void;
};
}

export interface CreateCodeGenSDKRuleArgs {
rule: string;
type: KeyType;
key: string;
expectedValue: string | boolean | RegExp;
exampleValue: string | boolean;
extraExplanation?: string;
condition?: (tspconfig: TypeSpecConfig, context: Rule.RuleContext) => boolean;
}
Loading
Loading