forked from Azure/typespec-azure
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Azure specs ruleset package (Azure#854)
implement Azure#654 Package designed to provide rulesets for azure specs. There is a test that makes sure for a given ruleset that all the rules from dependent linter are explicitly enabled or disabled. This will ensure that we don't forget to register rules there. --------- Co-authored-by: Mark Cowlishaw <[email protected]>
- Loading branch information
1 parent
9bad93e
commit a7ec279
Showing
18 changed files
with
456 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking | ||
changeKind: internal | ||
packages: | ||
- "@azure-tools/typespec-azure-rulesets" | ||
--- | ||
|
||
Initial version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
title: Overview | ||
sidebar_position: 0 | ||
toc_min_heading_level: 2 | ||
toc_max_heading_level: 3 | ||
--- | ||
|
||
import Tabs from '@theme/Tabs'; | ||
import TabItem from '@theme/TabItem'; | ||
|
||
# Overview | ||
|
||
TypeSpec ruleset for Azure specs | ||
|
||
## Install | ||
|
||
<Tabs> | ||
<TabItem value="spec" label="In a spec" default> | ||
|
||
```bash | ||
npm install @azure-tools/typespec-azure-rulesets | ||
``` | ||
|
||
</TabItem> | ||
<TabItem value="library" label="In a library" default> | ||
|
||
```bash | ||
npm install --save-peer @azure-tools/typespec-azure-rulesets | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
title: "Linter usage" | ||
toc_min_heading_level: 2 | ||
toc_max_heading_level: 3 | ||
--- | ||
|
||
# Linter | ||
|
||
## Usage | ||
|
||
Add the following in `tspconfig.yaml`: | ||
|
||
```yaml | ||
linter: | ||
extends: | ||
- "@azure-tools/typespec-azure-rulesets/data-plane" | ||
``` | ||
## RuleSets | ||
Available ruleSets: | ||
- `@azure-tools/typespec-azure-rulesets/data-plane` | ||
- `@azure-tools/typespec-azure-rulesets/resource-manager` | ||
|
||
## Rules | ||
|
||
| Name | Description | | ||
| ---- | ----------- | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) Microsoft Corporation. All rights reserved. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# @azure-tools/typespec-azure-rulesets | ||
|
||
TypeSpec ruleset for Azure specs | ||
|
||
## Install | ||
|
||
```bash | ||
npm install @azure-tools/typespec-azure-rulesets | ||
``` | ||
|
||
## Linter | ||
|
||
### Usage | ||
|
||
Add the following in `tspconfig.yaml`: | ||
|
||
```yaml | ||
linter: | ||
extends: | ||
- "@azure-tools/typespec-azure-rulesets/data-plane" | ||
``` | ||
### RuleSets | ||
Available ruleSets: | ||
- `@azure-tools/typespec-azure-rulesets/data-plane` | ||
- `@azure-tools/typespec-azure-rulesets/resource-manager` | ||
|
||
### Rules | ||
|
||
| Name | Description | | ||
| ---- | ----------- | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
{ | ||
"name": "@azure-tools/typespec-azure-rulesets", | ||
"version": "0.42.0", | ||
"author": "Microsoft Corporation", | ||
"description": "TypeSpec ruleset for Azure specs", | ||
"homepage": "https://azure.github.io/typespec-azure", | ||
"readme": "https://github.com/Azure/typespec-azure/blob/main/packages/typespec-azure-rulesets/README.md", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Azure/typespec-azure.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/Azure/typespec-azure/issues" | ||
}, | ||
"keywords": [ | ||
"typespec", | ||
"autorest" | ||
], | ||
"type": "module", | ||
"main": "dist/src/index.js", | ||
"exports": { | ||
".": "./dist/src/index.js" | ||
}, | ||
"engines": { | ||
"node": ">=18.0.0" | ||
}, | ||
"scripts": { | ||
"clean": "rimraf ./dist ./temp", | ||
"build": "tsc -p .", | ||
"watch": "tsc -p . --watch", | ||
"test": "vitest run", | ||
"test:watch": "vitest -w", | ||
"test:ui": "vitest --ui", | ||
"test:ci": "vitest run --coverage --reporter=junit --reporter=default", | ||
"lint": "eslint . --max-warnings=0", | ||
"lint:fix": "eslint . --fix ", | ||
"regen-docs": "tspd doc . --enable-experimental --output-dir ../../docs/emitters/typespec-azure-rulesets/reference" | ||
}, | ||
"files": [ | ||
"dist/**", | ||
"!dist/test/**" | ||
], | ||
"peerDependencies": { | ||
"@azure-tools/typespec-azure-core": "workspace:~", | ||
"@azure-tools/typespec-azure-resource-manager": "workspace:~", | ||
"@azure-tools/typespec-client-generator-core": "workspace:~", | ||
"@typespec/compiler": "workspace:~" | ||
}, | ||
"devDependencies": { | ||
"@azure-tools/typespec-azure-core": "workspace:~", | ||
"@azure-tools/typespec-azure-resource-manager": "workspace:~", | ||
"@azure-tools/typespec-client-generator-core": "workspace:~", | ||
"@types/node": "~18.11.19", | ||
"@typespec/compiler": "workspace:~", | ||
"@typespec/tspd": "workspace:~", | ||
"@vitest/coverage-v8": "^1.6.0", | ||
"@vitest/ui": "^1.6.0", | ||
"c8": "^9.1.0", | ||
"change-case": "~5.4.4", | ||
"rimraf": "~5.0.7", | ||
"typescript": "~5.4.5", | ||
"vitest": "^1.6.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { createTypeSpecLibrary, defineLinter } from "@typespec/compiler"; | ||
import dataPlaneRuleset from "./rulesets/data-plane.js"; | ||
import resourceManagerRuleset from "./rulesets/resource-manager.js"; | ||
|
||
export const $lib = createTypeSpecLibrary({ | ||
name: "@azure-tools/typespec-azure-rulesets", | ||
diagnostics: {}, | ||
}); | ||
|
||
export const $linter = defineLinter({ | ||
rules: [], | ||
ruleSets: { | ||
"data-plane": dataPlaneRuleset, | ||
"resource-manager": resourceManagerRuleset, | ||
}, | ||
}); |
42 changes: 42 additions & 0 deletions
42
packages/typespec-azure-rulesets/src/rulesets/data-plane.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import type { LinterRuleSet } from "@typespec/compiler"; | ||
|
||
export default { | ||
enable: { | ||
"@azure-tools/typespec-azure-core/operation-missing-api-version": true, | ||
"@azure-tools/typespec-azure-core/auth-required": true, | ||
"@azure-tools/typespec-azure-core/request-body-problem": true, | ||
"@azure-tools/typespec-azure-core/byos": true, | ||
"@azure-tools/typespec-azure-core/casing-style": true, | ||
"@azure-tools/typespec-azure-core/composition-over-inheritance": true, | ||
"@azure-tools/typespec-azure-core/use-extensible-enum": true, | ||
"@azure-tools/typespec-azure-core/known-encoding": true, | ||
"@azure-tools/typespec-azure-core/long-running-polling-operation-required": true, | ||
"@azure-tools/typespec-azure-core/no-closed-literal-union": true, | ||
"@azure-tools/typespec-azure-core/no-enum": true, | ||
"@azure-tools/typespec-azure-core/no-error-status-codes": true, | ||
"@azure-tools/typespec-azure-core/no-explicit-routes-resource-ops": true, | ||
"@azure-tools/typespec-azure-core/no-fixed-enum-discriminator": true, | ||
"@azure-tools/typespec-azure-core/non-breaking-versioning": true, | ||
"@azure-tools/typespec-azure-core/no-generic-numeric": true, | ||
"@azure-tools/typespec-azure-core/no-nullable": true, | ||
"@azure-tools/typespec-azure-core/no-offsetdatetime": true, | ||
"@azure-tools/typespec-azure-core/no-response-body": true, | ||
"@azure-tools/typespec-azure-core/no-rpc-path-params": true, | ||
"@azure-tools/typespec-azure-core/no-operation-id": true, | ||
"@azure-tools/typespec-azure-core/prefer-csv-collection-format": true, | ||
"@azure-tools/typespec-azure-core/no-format": true, | ||
"@azure-tools/typespec-azure-core/no-multiple-discriminator": true, | ||
"@azure-tools/typespec-azure-core/no-rest-library-interfaces": true, | ||
"@azure-tools/typespec-azure-core/no-unknown": true, | ||
"@azure-tools/typespec-azure-core/property-name-conflict": true, | ||
"@azure-tools/typespec-azure-core/bad-record-type": true, | ||
"@azure-tools/typespec-azure-core/documentation-required": true, | ||
"@azure-tools/typespec-azure-core/key-visibility-required": true, | ||
"@azure-tools/typespec-azure-core/response-schema-problem": true, | ||
"@azure-tools/typespec-azure-core/rpc-operation-request-body": true, | ||
"@azure-tools/typespec-azure-core/spread-discriminated-model": true, | ||
"@azure-tools/typespec-azure-core/use-standard-names": true, | ||
"@azure-tools/typespec-azure-core/use-standard-operations": true, | ||
"@azure-tools/typespec-azure-core/no-string-discriminator": true, | ||
}, | ||
} satisfies LinterRuleSet; |
77 changes: 77 additions & 0 deletions
77
packages/typespec-azure-rulesets/src/rulesets/resource-manager.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import type { LinterRuleSet } from "@typespec/compiler"; | ||
|
||
export default { | ||
enable: { | ||
// Azure core | ||
"@azure-tools/typespec-azure-core/operation-missing-api-version": true, | ||
"@azure-tools/typespec-azure-core/auth-required": true, | ||
"@azure-tools/typespec-azure-core/request-body-problem": true, | ||
"@azure-tools/typespec-azure-core/byos": true, | ||
"@azure-tools/typespec-azure-core/casing-style": true, | ||
"@azure-tools/typespec-azure-core/composition-over-inheritance": true, | ||
"@azure-tools/typespec-azure-core/use-extensible-enum": true, | ||
"@azure-tools/typespec-azure-core/known-encoding": true, | ||
"@azure-tools/typespec-azure-core/long-running-polling-operation-required": true, | ||
"@azure-tools/typespec-azure-core/no-closed-literal-union": true, | ||
"@azure-tools/typespec-azure-core/no-enum": true, | ||
"@azure-tools/typespec-azure-core/no-error-status-codes": true, | ||
"@azure-tools/typespec-azure-core/no-explicit-routes-resource-ops": true, | ||
"@azure-tools/typespec-azure-core/no-fixed-enum-discriminator": true, | ||
"@azure-tools/typespec-azure-core/non-breaking-versioning": true, | ||
"@azure-tools/typespec-azure-core/no-generic-numeric": true, | ||
"@azure-tools/typespec-azure-core/no-nullable": true, | ||
"@azure-tools/typespec-azure-core/no-offsetdatetime": true, | ||
"@azure-tools/typespec-azure-core/no-response-body": true, | ||
"@azure-tools/typespec-azure-core/no-rpc-path-params": true, | ||
"@azure-tools/typespec-azure-core/no-operation-id": true, | ||
"@azure-tools/typespec-azure-core/prefer-csv-collection-format": true, | ||
"@azure-tools/typespec-azure-core/no-format": true, | ||
"@azure-tools/typespec-azure-core/no-multiple-discriminator": true, | ||
"@azure-tools/typespec-azure-core/no-rest-library-interfaces": true, | ||
"@azure-tools/typespec-azure-core/no-unknown": true, | ||
"@azure-tools/typespec-azure-core/property-name-conflict": true, | ||
"@azure-tools/typespec-azure-core/documentation-required": true, | ||
"@azure-tools/typespec-azure-core/key-visibility-required": true, | ||
"@azure-tools/typespec-azure-core/response-schema-problem": true, | ||
"@azure-tools/typespec-azure-core/rpc-operation-request-body": true, | ||
"@azure-tools/typespec-azure-core/spread-discriminated-model": true, | ||
"@azure-tools/typespec-azure-core/use-standard-names": true, | ||
"@azure-tools/typespec-azure-core/use-standard-operations": true, | ||
"@azure-tools/typespec-azure-core/no-string-discriminator": true, | ||
|
||
// Azure core not enabled - Arm has its own conflicting rule | ||
"@azure-tools/typespec-azure-core/bad-record-type": false, | ||
|
||
// Azure resource manager | ||
"@azure-tools/typespec-azure-resource-manager/arm-no-record": true, | ||
"@azure-tools/typespec-azure-resource-manager/arm-common-types-version": true, | ||
"@azure-tools/typespec-azure-resource-manager/arm-delete-operation-response-codes": true, | ||
"@azure-tools/typespec-azure-resource-manager/arm-put-operation-response-codes": true, | ||
"@azure-tools/typespec-azure-resource-manager/arm-post-operation-response-codes": true, | ||
"@azure-tools/typespec-azure-resource-manager/arm-resource-action-no-segment": true, | ||
"@azure-tools/typespec-azure-resource-manager/arm-resource-duplicate-property": true, | ||
"@azure-tools/typespec-azure-resource-manager/arm-resource-invalid-envelope-property": true, | ||
"@azure-tools/typespec-azure-resource-manager/arm-resource-invalid-version-format": true, | ||
"@azure-tools/typespec-azure-resource-manager/arm-resource-key-invalid-chars": true, | ||
"@azure-tools/typespec-azure-resource-manager/arm-resource-name-pattern": true, | ||
"@azure-tools/typespec-azure-resource-manager/arm-resource-operation-response": true, | ||
"@azure-tools/typespec-azure-resource-manager/arm-resource-path-segment-invalid-chars": true, | ||
"@azure-tools/typespec-azure-resource-manager/arm-resource-provisioning-state": true, | ||
"@azure-tools/typespec-azure-resource-manager/beyond-nesting-levels": true, | ||
"@azure-tools/typespec-azure-resource-manager/arm-resource-operation": true, | ||
"@azure-tools/typespec-azure-resource-manager/no-resource-delete-operation": true, | ||
"@azure-tools/typespec-azure-resource-manager/empty-updateable-properties": true, | ||
"@azure-tools/typespec-azure-resource-manager/arm-resource-interface-requires-decorator": true, | ||
"@azure-tools/typespec-azure-resource-manager/arm-resource-invalid-action-verb": true, | ||
"@azure-tools/typespec-azure-resource-manager/improper-subscription-list-operation": true, | ||
"@azure-tools/typespec-azure-resource-manager/lro-location-header": true, | ||
"@azure-tools/typespec-azure-resource-manager/missing-x-ms-identifiers": true, | ||
"@azure-tools/typespec-azure-resource-manager/no-response-body": true, | ||
"@azure-tools/typespec-azure-resource-manager/missing-operations-endpoint": true, | ||
"@azure-tools/typespec-azure-resource-manager/patch-envelope": true, | ||
"@azure-tools/typespec-azure-resource-manager/arm-resource-patch": true, | ||
"@azure-tools/typespec-azure-resource-manager/resource-name": true, | ||
"@azure-tools/typespec-azure-resource-manager/retry-after": true, | ||
"@azure-tools/typespec-azure-resource-manager/unsupported-type": true, | ||
}, | ||
} satisfies LinterRuleSet; |
Oops, something went wrong.