Skip to content

Commit

Permalink
fix: Update schema generator (#5558)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S committed May 3, 2024
1 parent f565ead commit cf8029a
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 33 deletions.
105 changes: 99 additions & 6 deletions packages/cspell-eslint-plugin/assets/options.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,19 @@
"dictionaries": {
"description": "Optional list of dictionaries to use. Each entry should match the name of the dictionary.\n\nTo remove a dictionary from the list, add `!` before the name.\n\nFor example, `!typescript` will turn off the dictionary with the name `typescript`.\n\nSee the [Dictionaries](https://cspell.org/docs/dictionaries/) and [Custom Dictionaries](https://cspell.org/docs/dictionaries-custom/) for more details.",
"items": {
"description": "Reference to a dictionary by name. One of:\n- {@link DictionaryRef } \n- {@link DictionaryNegRef }",
"type": "string"
"anyOf": [
{
"description": "This a reference to a named dictionary. It is expected to match the name of a dictionary.",
"pattern": "^(?=[^!*,;{}[\\]~\\n]+$)(?=(.*\\w)).+$",
"type": "string"
},
{
"description": "This a negative reference to a named dictionary.\n\nIt is used to exclude or include a dictionary by name.\n\nThe reference starts with 1 or more `!`.\n- `!<dictionary_name>` - Used to exclude the dictionary matching `<dictionary_name>`.\n- `!!<dictionary_name>` - Used to re-include a dictionary matching `<dictionary_name>`. Overrides `!<dictionary_name>`.\n- `!!!<dictionary_name>` - Used to exclude a dictionary matching `<dictionary_name>`. Overrides `!!<dictionary_name>`.",
"pattern": "^(?=!+[^!*,;{}[\\]~\\n]+$)(?=(.*\\w)).+$",
"type": "string"
}
],
"description": "Reference to a dictionary by name. One of:\n- {@link DictionaryRef } \n- {@link DictionaryNegRef }"
},
"type": "array"
},
Expand Down Expand Up @@ -126,8 +137,49 @@
"ignoreRegExpList": {
"description": "List of regular expression patterns or pattern names to exclude from spell checking.\n\nExample: `[\"href\"]` - to exclude html href pattern.\n\nRegular expressions use JavaScript regular expression syntax.\n\nExample: to ignore ALL-CAPS words\n\nJSON ```json \"ignoreRegExpList\": [\"/\\\\b[A-Z]+\\\\b/g\"] ```\n\nYAML ```yaml ignoreRegExpList: - >- /\\b[A-Z]+\\b/g ```\n\nBy default, several patterns are excluded. See [Configuration](https://cspell.org/configuration/patterns) for more details.\n\nWhile you can create your own patterns, you can also leverage several patterns that are [built-in to CSpell](https://cspell.org/types/cspell-types/types/PredefinedPatterns.html).",
"items": {
"description": "A PatternRef is a Pattern or PatternId.",
"type": "string"
"anyOf": [
{
"type": "string"
},
{
"description": "This matches the name in a pattern definition.",
"type": "string"
},
{
"enum": [
"Base64",
"Base64MultiLine",
"Base64SingleLine",
"CStyleComment",
"CStyleHexValue",
"CSSHexValue",
"CommitHash",
"CommitHashLink",
"Email",
"EscapeCharacters",
"HexValues",
"href",
"PhpHereDoc",
"PublicKey",
"RsaCert",
"SshRsa",
"SHA",
"HashStrings",
"SpellCheckerDisable",
"SpellCheckerDisableBlock",
"SpellCheckerDisableLine",
"SpellCheckerDisableNext",
"SpellCheckerIgnoreInDocSetting",
"string",
"UnicodeRef",
"Urls",
"UUID",
"Everything"
],
"type": "string"
}
],
"description": "A PatternRef is a Pattern or PatternId."
},
"type": "array"
},
Expand Down Expand Up @@ -157,8 +209,49 @@
"includeRegExpList": {
"description": "List of regular expression patterns or defined pattern names to match for spell checking.\n\nIf this property is defined, only text matching the included patterns will be checked.\n\nWhile you can create your own patterns, you can also leverage several patterns that are [built-in to CSpell](https://cspell.org/types/cspell-types/types/PredefinedPatterns.html).",
"items": {
"description": "A PatternRef is a Pattern or PatternId.",
"type": "string"
"anyOf": [
{
"type": "string"
},
{
"description": "This matches the name in a pattern definition.",
"type": "string"
},
{
"enum": [
"Base64",
"Base64MultiLine",
"Base64SingleLine",
"CStyleComment",
"CStyleHexValue",
"CSSHexValue",
"CommitHash",
"CommitHashLink",
"Email",
"EscapeCharacters",
"HexValues",
"href",
"PhpHereDoc",
"PublicKey",
"RsaCert",
"SshRsa",
"SHA",
"HashStrings",
"SpellCheckerDisable",
"SpellCheckerDisableBlock",
"SpellCheckerDisableLine",
"SpellCheckerDisableNext",
"SpellCheckerIgnoreInDocSetting",
"string",
"UnicodeRef",
"Urls",
"UUID",
"Everything"
],
"type": "string"
}
],
"description": "A PatternRef is a Pattern or PatternId."
},
"type": "array"
},
Expand Down
9 changes: 6 additions & 3 deletions packages/cspell-eslint-plugin/fixtures/cspell.config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
ignorePaths:
ignorePaths: # glob patterns to ignore
- cspell*.{yaml,json}
ignoreWords:
- node_modules
words: # words to add to dictionary
- MyCompanyName
ignoreWords: # words to ignore, but not suggest
- todos
flagWords:
flagWords: # words to flag as forbidden with suggestions.
- blacklist->denylist
- whitelist->allowlist
- café->cafe
Expand Down
2 changes: 1 addition & 1 deletion packages/cspell-eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"eslint-plugin-simple-import-sort": "^12.1.0",
"globals": "^15.1.0",
"mocha": "^10.4.0",
"ts-json-schema-generator": "^1.5.1",
"ts-json-schema-generator": "^2.1.1",
"typescript": "^5.4.5",
"typescript-eslint": "^7.8.0"
},
Expand Down
11 changes: 11 additions & 0 deletions packages/cspell-eslint-plugin/src/test/index.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ ruleTester.run('cspell', Rule.rules.spellchecker, {
'Unknown word: "coool"',
'Unknown word: "coool"',
]),
readInvalid(
'with-errors/sampleESM.mjs',
[
'Unknown word: "Gallaxy"',
'Unknown word: "BADD"',
'Unknown word: "functionn"',
'Unknown word: "coool"',
'Unknown word: "coool"',
],
{ cspell: { ignoreRegExpList: ['/\\bGuuide\\b/g'] } },
),
readInvalid(
'with-errors/sampleESM.mjs',
['Unknown word: "Guuide"', 'Unknown word: "Gallaxy"', 'Unknown word: "functionn"', 'Unknown word: "coool"'],
Expand Down
24 changes: 16 additions & 8 deletions packages/cspell-io/src/node/file/stat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ describe('stat', () => {
url | expected
${'https://raw.githubusercontent.com/streetsidesoftware/cspell/main/tsconfig.json'} | ${oc({ eTag: sc('W/') })}
${__filename} | ${oc({ mtimeMs: expect.any(Number) })}
`('getStat $url', async ({ url, expected }) => {
const r = await getStat(url);
expect(r).toEqual(expected);
});
`(
'getStat $url',
async ({ url, expected }) => {
const r = await getStat(url);
expect(r).toEqual(expected);
},
timeout,
);

test.each`
url | expected
Expand Down Expand Up @@ -45,8 +49,12 @@ describe('stat', () => {
url | expected
${'https://www.google.com/404'} | ${oc({ code: 'ENOENT' })}
${join(__dirname, 'not-found.nf')} | ${oc({ code: 'ENOENT' })}
`('getStatSync with error $url', async ({ url, expected }) => {
const r = await getStatSync(url);
expect(r).toEqual(expected);
});
`(
'getStatSync with error $url',
async ({ url, expected }) => {
const r = await getStatSync(url);
expect(r).toEqual(expected);
},
timeout,
);
});
2 changes: 1 addition & 1 deletion packages/cspell-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"devDependencies": {
"@types/glob": "^8.1.0",
"lorem-ipsum": "^2.0.8",
"ts-json-schema-generator": "^1.5.1"
"ts-json-schema-generator": "^2.1.1"
},
"module": "bin.mjs"
}
7 changes: 6 additions & 1 deletion packages/cspell-types/src/DictionaryInformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,16 @@ export interface CharacterSetCosts {
penalty?: number;
}

/**
* @hidden
*/
export type IRegExp = RegExp;

export interface PatternAdjustment {
/** Id of the Adjustment, i.e. `short-compound` */
id: string;
/** RegExp pattern to match */
regexp: string | RegExp;
regexp: string | IRegExp;
/** The amount of penalty to apply. */
penalty: number;
}
22 changes: 12 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions scripts/build-cspell-schema.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as path from 'node:path';
import { fileURLToPath } from 'node:url';

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

const importDir = new URL('.', import.meta.url);
const rootUrl = new URL('..', importDir);
Expand Down Expand Up @@ -54,7 +54,7 @@ async function run() {
skipTypeCheck: true,
};

const schema = tsj.createGenerator(config).createSchema(config.type);
const schema = createGenerator(config).createSchema(config.type);
schema.allowTrailingCommas = true;
const stringify = config.sortProps ? safeStableStringify : JSON.stringify;
const schemaString = stringify(schema, undefined, 2);
Expand Down
2 changes: 1 addition & 1 deletion scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
"dependencies": {
"globby": "^14.0.1",
"safe-stable-stringify": "^2.4.3",
"ts-json-schema-generator": "^1.5.1"
"ts-json-schema-generator": "^2.1.1"
}
}

0 comments on commit cf8029a

Please sign in to comment.