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

fix: suggestWords dict schema validation #5786

Merged
merged 2 commits into from
Jun 20, 2024
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
204 changes: 140 additions & 64 deletions cspell.schema.json

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@
"build-dev": "pnpm run --filter \\!website build-dev",
"build-cspell-types-docs": "cd doc-generator && pnpm i && pnpm run build-cspell-types-docs",
"build-integration-tests": "cd ./integration-tests && pnpm i",
"build-schema": "pnpm -r run build-schema && pnpm build:clean-up-schema",
"build": "pnpm -r --stream --workspace-concurrency=2 run build && pnpm -r run prepare-cspell-action && pnpm build:clean-up-schema",
"build-schema": "pnpm -r run build-schema",
"build": "pnpm -r --stream --workspace-concurrency=2 run build && pnpm -r run prepare-cspell-action",
"build:readme": "pnpm build:readme:packages && pnpm build:readme:root && pnpm docs:inject",
"build:readme:packages": "pnpm -r build:readme",
"build:readme:root": "inject-markdown README.md \"packages/*/README.md\" && prettier -w README.md \"packages/*/README.md\"",
"build:clean-up-schema": "node ./scripts/remove-zero-width-space.mjs ./cspell.schema.json",
"docs:inject": "inject-markdown \"docs/**/*.md\" && pnpm lint-docs",
"check-spelling": "npx cspell -c cspell.test.all.json",
"clean-build": "pnpm run clean && pnpm -r --stream --workspace-concurrency=2 run build",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export interface SpellingDictionaryOptions {
/**
* This is a NO Suggest dictionary used for words to be ignored.
*/
noSuggest?: boolean;
noSuggest?: boolean | undefined;
/**
* Extra dictionary information used in improving suggestions
* based upon locale.
Expand Down
61 changes: 53 additions & 8 deletions packages/cspell-eslint-plugin/assets/options.schema.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion packages/cspell-eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
"bt": "pnpm build && pnpm test",
"build": "pnpm build:schema && pnpm build:src",
"build:src": "tsc -b ./tsconfig.json -f",
"build:schema": "ts-json-schema-generator --no-top-ref --expose none --path src/common/options.cts --type Options -o ./assets/options.schema.json",
"build:schema": "pnpm build-options-schema",
"build:schema:old": "ts-json-schema-generator --no-top-ref --expose none --path src/common/options.cts --type Options -o ./assets/options.schema.json",
"watch": "tsc -b ./tsconfig.json --watch -f",
"clean": "shx rm -rf dist temp coverage \"*.tsbuildInfo\"",
"clean-build": "pnpm run clean && pnpm run build",
Expand All @@ -78,6 +79,7 @@
"devDependencies": {
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.5.0",
"@internal/cspell-eslint-plugin-scripts": "workspace:*",
"@types/estree": "^1.0.5",
"@types/mocha": "^10.0.6",
"@typescript-eslint/parser": "^7.13.1",
Expand Down
66 changes: 66 additions & 0 deletions packages/cspell-eslint-plugin/scripts/build-options-schema.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env node

// @ts-check
import { writeFile } from 'node:fs/promises';
import * as path from 'node:path';
import { fileURLToPath } from 'node:url';

import safeStableStringify from 'safe-stable-stringify';
import { createGenerator } from 'ts-json-schema-generator';

const importDir = new URL('.', import.meta.url);
const rootUrl = new URL('..', importDir);
const typesDirUrl = new URL('src/common', rootUrl);
const outFile = 'assets/options.schema.json';
const typesDir = fileURLToPath(typesDirUrl);

/** @type {import('ts-json-schema-generator').Config} */
const defaultConfig = {
expose: 'none',
topRef: true,
jsDoc: 'extended',
markdownDescription: true,
sortProps: true,
strictTuples: false,
skipTypeCheck: false,
encodeRefs: true,
minify: false,
extraTags: [],
additionalProperties: false,
discriminatorType: 'json-schema',
};

/**
* Build the schema. This method replaces the old command line that was run in `packages/cspell-types`
* ```sh
* ts-json-schema-generator \
* --no-top-ref \
* --expose none \
* --validation-keywords markdownDescription \
* --validation-keywords deprecated \
* --validation-keywords deprecationMessage \
* --path src/common/options.cts \
* --type Options \
* -o ./assets/options.schema.json
* ```
*/
async function run() {
/** @type {import('ts-json-schema-generator').Config} */
const config = {
...defaultConfig,
path: path.join(typesDir, 'src/options.cts'),
tsconfig: path.join(typesDir, './tsconfig.json'),
type: 'Options',
topRef: false,
extraTags: ['deprecated', 'deprecationMessage'],
skipTypeCheck: true,
};

const schema = createGenerator(config).createSchema(config.type);
const stringify = config.sortProps ? safeStableStringify : JSON.stringify;
const schemaString = stringify(schema, undefined, 2)?.replaceAll('\u200B', '');

await writeFile(new URL(outFile, rootUrl), schemaString);
}

run();
8 changes: 8 additions & 0 deletions packages/cspell-eslint-plugin/scripts/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"lib": ["es2023"]
}
}
24 changes: 24 additions & 0 deletions packages/cspell-eslint-plugin/scripts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "@internal/cspell-eslint-plugin-scripts",
"private": true,
"version": "1.0.0",
"description": "Tools and Scripts",
"type": "module",
"bin": {
"build-options-schema": "./build-options-schema.mjs"
},
"scripts": {
"test": "echo Ok"
},
"keywords": [],
"author": "",
"license": "MIT",
"engines": {
"node": ">=18.0"
},
"devDependencies": {},
"dependencies": {
"safe-stable-stringify": "^2.4.3",
"ts-json-schema-generator": "^2.3.0"
}
}
Loading