Skip to content

Commit

Permalink
Merge 336f850 into e623988
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S committed Jan 12, 2022
2 parents e623988 + 336f850 commit 3a50357
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 0 deletions.
1 change: 1 addition & 0 deletions lerna.json
@@ -1,6 +1,7 @@
{
"packages": [
"packages/*",
"rfc/*",
"test-packages/*",
"integration-tests"
],
Expand Down
91 changes: 91 additions & 0 deletions rfc/rfc-0001 suggestions/README.md
@@ -0,0 +1,91 @@
# Suggestion Lists

## Flag Words

The idea is to enhance the definition of `flagWords` to allow for suggestions.

### Type Definitions

Replace the definition of `flagWords` with the following:

```ts
type FlagWordNoSuggestions = string;
type FlagWordWithSuggestions = [forbidWord: string, suggestion: string, ...otherSuggestions: string[]];
type FlagWord = FlagWordNoSuggestions | FlagWordWithSuggestions;
type FlagWords = FlagWord[];

interface BaseSettings {
// ... other fields
flagWords?: FlagWords;
}
```

### Usage:

```yaml
flagWords:
- crap
- [hte, the]
- [acadmic, academic]
- [accension, accession, ascension]
```

```json
"flagWords": [
"crap",
["hte", "the"],
["acadmic", "academic"],
["accension", "accession", "ascension"]
]
```

## Suggestion Dictionary

Be able to leverage lists like:

- [Wikipedia:Lists of common misspellings/For machines - Wikipedia](https://en.wikipedia.org/wiki/Wikipedia:Lists_of_common_misspellings/For_machines)

Using a suggestions dictionary provides several useful features:

- The word list is in a separate file
- Multiple formats can be supported
- Named dictionaries can be turned on, off, or even redefined

### File formats

The file format is generally inferred based upon the file extension. All files can be `gzip`d and will have a `.gz` final extension.

#### Text File Format

One suggestion set per line.

Example:

<!--- cspell:disable -->

```txt
againnst->against
agains->against
agaisnt -> against
aganist-> against
aggaravates->aggravates
alusion->allusion, illusion
alwasy->always
alwyas->always
amalgomated->amalgamated
amatuer->amateur
amature->armature, amateur
boaut->boat, bout, about
```

Validation:

```regexp
/^(\p{L}+)\s*->\s*(\p{L}+)(?:,\s*(\p{L}+))*$/gmu
```

![image](https://user-images.githubusercontent.com/3740137/149126237-455c6674-ed1f-4dd8-8136-083531d2c63b.png)

<!--- cspell:enable -->

<!--- cspell:ignore acadmic accension -->
1 change: 1 addition & 0 deletions rfc/rfc-0001 suggestions/jest.config.js
@@ -0,0 +1 @@
module.exports = require('../../jest.config');
31 changes: 31 additions & 0 deletions rfc/rfc-0001 suggestions/package-lock.json

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

16 changes: 16 additions & 0 deletions rfc/rfc-0001 suggestions/package.json
@@ -0,0 +1,16 @@
{
"name": "rfc-0001-suggestions",
"version": "1.0.0",
"description": "Possible ways to support suggestion lists",
"private": true,
"scripts": {
"build": "tsc -p .",
"test": ""
},
"files": [],
"author": "",
"license": "MIT",
"dependencies": {
"@cspell/cspell-types": "^5.15.2"
}
}
34 changes: 34 additions & 0 deletions rfc/rfc-0001 suggestions/src/config-definitions.ts
@@ -0,0 +1,34 @@
import type { DictionaryDefinitionPreferred, BaseSetting } from '@cspell/cspell-types';

export interface DictionaryDefinitionSuggestions extends Omit<DictionaryDefinitionPreferred, 'type'> {
type: 'suggestions';
}

const exampleDef: DictionaryDefinitionSuggestions = {
name: 'en-us-suggestions',
path: './en-suggestions.txt.gz',
type: 'suggestions',
};

/*********************/

type FlagWordNoSuggestions = string;
type FlagWordWithSuggestions = [forbidWord: string, suggestion: string, ...otherSuggestions: string[]];
type FlagWord = FlagWordNoSuggestions | FlagWordWithSuggestions;
export type FlagWords = FlagWord[];

// Changes to BaseSettings:
export interface NewBaseSettings extends Omit<BaseSetting, 'flagWords'> {
flagWords?: FlagWords;
}

const exampleFlagWords: NewBaseSettings = {
flagWords: ['crap', ['hte', 'the']],
};

/*********************/

export const __testing__ = {
exampleDef,
exampleFlagWords,
};
10 changes: 10 additions & 0 deletions rfc/rfc-0001 suggestions/tsconfig.json
@@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist"
},
"include": [
"src/**/*.ts",
"src/**/*.test.ts"
]
}

0 comments on commit 3a50357

Please sign in to comment.