Skip to content

Commit

Permalink
chore: add schemas for rules and tags (#1335)
Browse files Browse the repository at this point in the history
  • Loading branch information
nayeemrmn authored Oct 24, 2024
1 parent f3fc061 commit 811b397
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ jobs:
if: contains(matrix.os, 'ubuntu')
run: diff <(./target/release/examples/dlint rules --json) www/static/docs.json

- name: Check if schemas are up-to-date
if: contains(matrix.os, 'ubuntu')
run: deno run --allow-run --allow-read=schemas --allow-write=schemas tools/generate_schemas.ts --check

- name: Benchmarks
if: contains(matrix.os, 'ubuntu')
run: deno run -A --quiet benchmarks/benchmarks.ts
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ on:
workflow_dispatch:
inputs:
releaseKind:
description: 'Kind of release'
default: 'minor'
description: "Kind of release"
default: "minor"
type: choice
options:
- patch
Expand Down
3 changes: 2 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"lock": false,
"tasks": {
"update-docs": "cargo run --features=docs --example dlint rules --json > www/static/docs.json"
"update-docs": "cargo run --features=docs --example dlint rules --json > www/static/docs.json",
"update-schemas": "deno run --allow-run --allow-read=schemas --allow-write=schemas tools/generate_schemas.ts"
},
"exclude": [
"target",
Expand Down
112 changes: 112 additions & 0 deletions schemas/rules.v1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"enum": [
"adjacent-overload-signatures",
"ban-ts-comment",
"ban-types",
"ban-unknown-rule-code",
"ban-untagged-ignore",
"ban-untagged-todo",
"ban-unused-ignore",
"camelcase",
"constructor-super",
"default-param-last",
"eqeqeq",
"explicit-function-return-type",
"explicit-module-boundary-types",
"for-direction",
"fresh-handler-export",
"fresh-server-event-handlers",
"getter-return",
"guard-for-in",
"no-array-constructor",
"no-async-promise-executor",
"no-await-in-loop",
"no-await-in-sync-fn",
"no-boolean-literal-for-arguments",
"no-case-declarations",
"no-class-assign",
"no-compare-neg-zero",
"no-cond-assign",
"no-console",
"no-const-assign",
"no-constant-condition",
"no-control-regex",
"no-debugger",
"no-delete-var",
"no-deprecated-deno-api",
"no-dupe-args",
"no-dupe-class-members",
"no-dupe-else-if",
"no-dupe-keys",
"no-duplicate-case",
"no-empty",
"no-empty-character-class",
"no-empty-enum",
"no-empty-interface",
"no-empty-pattern",
"no-eval",
"no-ex-assign",
"no-explicit-any",
"no-external-import",
"no-extra-boolean-cast",
"no-extra-non-null-assertion",
"no-fallthrough",
"no-func-assign",
"no-global-assign",
"no-implicit-declare-namespace-export",
"no-import-assertions",
"no-import-assign",
"no-inferrable-types",
"no-inner-declarations",
"no-invalid-regexp",
"no-invalid-triple-slash-reference",
"no-irregular-whitespace",
"no-misused-new",
"no-namespace",
"no-new-symbol",
"no-node-globals",
"no-non-null-asserted-optional-chain",
"no-non-null-assertion",
"no-obj-calls",
"no-octal",
"no-process-globals",
"no-prototype-builtins",
"no-redeclare",
"no-regex-spaces",
"no-self-assign",
"no-self-compare",
"no-setter-return",
"no-shadow-restricted-names",
"no-sloppy-imports",
"no-slow-types",
"no-sparse-arrays",
"no-sync-fn-in-async-fn",
"no-this-alias",
"no-this-before-super",
"no-throw-literal",
"no-top-level-await",
"no-undef",
"no-unreachable",
"no-unsafe-finally",
"no-unsafe-negation",
"no-unused-labels",
"no-unused-vars",
"no-var",
"no-window",
"no-window-prefix",
"no-with",
"prefer-as-const",
"prefer-ascii",
"prefer-const",
"prefer-namespace-keyword",
"prefer-primordials",
"require-await",
"require-yield",
"single-var-declarator",
"triple-slash-reference",
"use-isnan",
"valid-typeof",
"verbatim-module-syntax"
]
}
4 changes: 4 additions & 0 deletions schemas/tags.v1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"enum": ["fresh", "jsr", "recommended"]
}
49 changes: 49 additions & 0 deletions tools/generate_schemas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { assertEquals } from "jsr:@std/[email protected]";

const check = Deno.args.includes("--check");

const rulesOutput = await new Deno.Command("cargo", {
args: ["run", "--features=docs", "--example", "dlint", "rules", "--json"],
}).output();
if (!rulesOutput.success) {
throw new Error("Command failed: dlint rules --json");
}
const rulesOutputText = new TextDecoder().decode(rulesOutput.stdout);
const ruleEntries = JSON.parse(rulesOutputText);
const rules = new Set();
const tags = new Set();
for (const rule of ruleEntries) {
rules.add(rule.code);
for (const tag of rule.tags) {
tags.add(tag);
}
}
// These rules are implemented in CLI.
rules.add("no-sloppy-imports");
rules.add("no-slow-types");
const rulesSchema = {
"$schema": "http://json-schema.org/draft-07/schema#",
"enum": [...rules].sort(),
};
const tagsSchema = {
"$schema": "http://json-schema.org/draft-07/schema#",
"enum": [...tags].sort(),
};

const rulesUrl = new URL("../schemas/rules.v1.json", import.meta.url);
const tagsUrl = new URL("../schemas/tags.v1.json", import.meta.url);
if (check) {
const existingRulesSchema = JSON.parse(await Deno.readTextFile(rulesUrl));
const existingTagsSchema = JSON.parse(await Deno.readTextFile(tagsUrl));
assertEquals(existingRulesSchema, rulesSchema);
assertEquals(existingTagsSchema, tagsSchema);
} else {
await Deno.writeTextFile(rulesUrl, JSON.stringify(rulesSchema));
await Deno.writeTextFile(tagsUrl, JSON.stringify(tagsSchema));
const fmtOutput = await new Deno.Command("deno", {
args: ["fmt", rulesUrl.toString(), tagsUrl.toString()],
}).output();
if (!fmtOutput.success) {
throw new Error("Command failed: deno fmt");
}
}

0 comments on commit 811b397

Please sign in to comment.