Skip to content

Commit 64a94f5

Browse files
authored
Merge pull request #1185 from pjkaufman/master
Move Default Auto-Correct Misspellings to Separate File
2 parents 7e888a5 + bac7567 commit 64a94f5

File tree

15 files changed

+35314
-35188
lines changed

15 files changed

+35314
-35188
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
- name: Create Manual Install Zip
2929
run: |
3030
mkdir ${{ env.PLUGIN_NAME }}
31-
cp main.js manifest.json src/styles.css ${{ env.PLUGIN_NAME }}
31+
cp main.js manifest.json src/styles.css src/utils/default-misspellings.md ${{ env.PLUGIN_NAME }}
3232
zip -r ${{ env.PLUGIN_NAME }}.zip ${{ env.PLUGIN_NAME }}
3333
3434
- name: Create release

__tests__/auto-correct-common-misspellings.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import AutoCorrectCommonMisspellings from '../src/rules/auto-correct-common-misspellings';
22
import dedent from 'ts-dedent';
3-
import {ruleTest} from './common';
3+
import {defaultMisspellings, ruleTest} from './common';
44

55
ruleTest({
66
RuleBuilderClass: AutoCorrectCommonMisspellings,
@@ -15,6 +15,9 @@ ruleTest({
1515
[[absoltely not a changed]]
1616
[absoltely not a changed](absoltely.not.changed.md)
1717
`,
18+
options: {
19+
misspellingToCorrection: defaultMisspellings(),
20+
},
1821
},
1922
{
2023
testName: 'Doesn\'t auto-correct markdown and wiki images',
@@ -26,6 +29,9 @@ ruleTest({
2629
![[absoltely.not.a.changed.jpg]]
2730
![absoltely not a changed](absoltely.not.changed.md)
2831
`,
32+
options: {
33+
misspellingToCorrection: defaultMisspellings(),
34+
},
2935
},
3036
{
3137
testName: 'Doesn\'t auto-correct words that start with unicode specific characters when not in correction list',
@@ -35,6 +41,9 @@ ruleTest({
3541
after: dedent`
3642
être
3743
`,
44+
options: {
45+
misspellingToCorrection: defaultMisspellings(),
46+
},
3847
},
3948
{
4049
testName: 'Custom replacements should work on file content',
@@ -45,6 +54,7 @@ ruleTest({
4554
The cart is over there.
4655
`,
4756
options: {
57+
misspellingToCorrection: defaultMisspellings(),
4858
extraAutoCorrectFiles: [{
4959
filePath: 'file_path',
5060
customReplacements: new Map<string, string>([['cartt', 'cart'], ['theree', 'there']]),

__tests__/common.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
1+
import {readFileSync} from 'fs';
12
import {Options} from '../src/rules';
23
import RuleBuilder, {RuleBuilderBase} from '../src/rules/rule-builder';
4+
import {parseCustomReplacements} from '../src/utils/strings';
5+
6+
let defaultMap: Map<string, string>;
7+
8+
export function defaultMisspellings(): Map<string, string> {
9+
if (!defaultMap) {
10+
const data = readFileSync('src/utils/default-misspellings.md', 'utf8');
11+
defaultMap = parseCustomReplacements(data);
12+
}
13+
14+
return defaultMap;
15+
}
316

417
type TestCase<TOptions extends Options> = {
518
testName: string,

__tests__/examples.test.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@ import dedent from 'ts-dedent';
22
import {Example, rules, RuleType} from '../src/rules';
33
import {yamlRegex, escapeRegExp} from '../src/utils/regex';
44
import '../src/rules-registry';
5+
import {defaultMisspellings} from './common';
56

67
describe('Examples pass', () => {
78
for (const rule of rules) {
89
describe(rule.getName(), () => {
910
test.each(rule.examples)('$description', (example: Example) => {
10-
expect(rule.apply(example.before, example.options)).toBe(example.after);
11+
const options = example.options;
12+
// add default misspellings for auto-correct
13+
if (rule.alias == 'auto-correct-common-misspellings') {
14+
options.misspellingToCorrection = defaultMisspellings();
15+
}
16+
17+
expect(rule.apply(example.before, options)).toBe(example.after);
1118
});
1219
});
1320
}
@@ -27,7 +34,14 @@ describe('Augmented examples pass', () => {
2734
`;
2835

2936
const before = yaml + example.before;
30-
expect(rule.apply(before, example.options)).toMatch(new RegExp(`${escapeRegExp(yaml)}\n?${escapeRegExp(example.after)}`));
37+
38+
const options = example.options;
39+
// add default misspellings for auto-correct
40+
if (rule.alias == 'auto-correct-common-misspellings') {
41+
options.misspellingToCorrection = defaultMisspellings();
42+
}
43+
44+
expect(rule.apply(before, options)).toMatch(new RegExp(`${escapeRegExp(yaml)}\n?${escapeRegExp(example.after)}`));
3145
}
3246
});
3347
});

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lang/locale/de.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ export default {
224224
// auto-correct-common-misspellings.ts
225225
'auto-correct-common-misspellings': {
226226
'name': 'Häufige Rechtschreibfehler automatisch korrigieren',
227-
'description': 'Verwendet ein Wörterbuch mit häufigen Rechtschreibfehlern, um sie automatisch in die richtige Schreibweise umzuwandeln. Siehe [Autokorrekturkarte](https://github.com/platers/obsidian-linter/tree/master/src/utils/auto-correct-misspellings.ts) für die vollständige Liste der automatisch korrigierten Wörter.',
227+
'description': 'Verwendet ein Wörterbuch mit häufigen Rechtschreibfehlern, um sie automatisch in die richtige Schreibweise umzuwandeln. Siehe [Autokorrekturkarte](https://github.com/platers/obsidian-linter/tree/master/src/utils/default-misspellings.md) für die vollständige Liste der automatisch korrigierten Wörter.',
228228
'ignore-words': {
229229
'name': 'Ignorieren Sie Wörter',
230230
'description': 'Eine durch Kommas getrennte Liste von Wörtern in Kleinbuchstaben, die bei der automatischen Korrektur ignoriert werden sollen',

src/lang/locale/en.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ export default {
263263
// auto-correct-common-misspellings.ts
264264
'auto-correct-common-misspellings': {
265265
'name': 'Auto-correct Common Misspellings',
266-
'description': 'Uses a dictionary of common misspellings to automatically convert them to their proper spellings. See [auto-correct map](https://github.com/platers/obsidian-linter/tree/master/src/utils/auto-correct-misspellings.ts) for the full list of auto-corrected words. **Note: this list can work on text from multiple languages, but this list is the same no matter what language is currently in use.**',
266+
'description': 'Uses a dictionary of common misspellings to automatically convert them to their proper spellings. See [auto-correct map](https://github.com/platers/obsidian-linter/tree/master/src/utils/default-misspellings.md) for the full list of auto-corrected words. **Note: this list can work on text from multiple languages, but this list is the same no matter what language is currently in use.**',
267267
'ignore-words': {
268268
'name': 'Ignore Words',
269269
'description': 'A comma separated list of lowercased words to ignore when auto-correcting',
@@ -276,6 +276,9 @@ export default {
276276
'name': 'Skip Words with Multiple Capitals',
277277
'description': 'Will skip any files that have a capital letter in them other than as the first letter of the word. Acronyms and some other words can benefit from this. It may cause issues with proper nouns being properly fixed.',
278278
},
279+
'default-install': 'You are using Auto-correct Common Misspellings. In order to do so, the default misspellings will be downloaded. This should only happen once. Please wait...',
280+
'default-install-failed': 'Failed to download {URL}. Disabling Auto-correct Common Misspellings.',
281+
'defaults-missing': 'Failed to find default common auto-correct file: {FILE}.',
279282
},
280283
// add-blank-line-after-yaml.ts
281284
'add-blank-line-after-yaml': {

src/lang/locale/es.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export default {
189189
'rules': {
190190
'auto-correct-common-misspellings': {
191191
'name': 'Corrección automática de errores ortográficos comunes',
192-
'description': 'Utiliza un diccionario de errores ortográficos comunes para convertirlos automáticamente a su ortografía correcta. Consulte [mapa de autocorrección](https://github.com/platers/obsidian-linter/tree/master/src/utils/auto-correct-misspellings.ts) para obtener la lista completa de palabras corregidas automáticamente. **Nota: esta lista puede funcionar en texto de varios idiomas, pero esta lista es la misma sin importar qué idioma esté en uso actualmente.**',
192+
'description': 'Utiliza un diccionario de errores ortográficos comunes para convertirlos automáticamente a su ortografía correcta. Consulte [mapa de autocorrección](https://github.com/platers/obsidian-linter/tree/master/src/utils/default-misspellings.md) para obtener la lista completa de palabras corregidas automáticamente. **Nota: esta lista puede funcionar en texto de varios idiomas, pero esta lista es la misma sin importar qué idioma esté en uso actualmente.**',
193193
'ignore-words': {
194194
'name': 'Ignorar palabras',
195195
'description': 'Una lista separada por comas de palabras en minúsculas para ignorar al corregir automáticamente',

src/lang/locale/tr.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ export default {
220220
// auto-correct-common-misspellings.ts
221221
'auto-correct-common-misspellings': {
222222
'name': 'Yaygın Yanlış Yazımları Otomatik Düzelt',
223-
'description': 'Yaygın yanlış yazımların sözlüğünü kullanarak bunları doğru yazımlarına otomatik olarak dönüştürür. Otomatik düzeltilen kelimelerin tam listesi için [otomatik-düzeltme haritasına](https://github.com/platers/obsidian-linter/tree/master/src/utils/auto-correct-misspellings.ts) bakın.',
223+
'description': 'Yaygın yanlış yazımların sözlüğünü kullanarak bunları doğru yazımlarına otomatik olarak dönüştürür. Otomatik düzeltilen kelimelerin tam listesi için [otomatik-düzeltme haritasına](https://github.com/platers/obsidian-linter/tree/master/src/utils/default-misspellings.md) bakın.',
224224
'ignore-words': {
225225
'name': 'Kelimeleri Yoksay',
226226
'description': 'Otomatik düzeltme sırasında yoksayılacak küçük harfli kelimelerin virgülle ayrılmış listesi',

src/lang/locale/zh-cn.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ export default {
220220
// auto-correct-common-misspellings.ts
221221
'auto-correct-common-misspellings': {
222222
'name': '自动更正常见的拼写错误',
223-
'description': '通过常见拼写错误字典自动将错误拼写更正为正确拼写。有关自动更正单词的完整列表,请参阅 [auto-correct map](https://github.com/platers/obsidian-linter/tree/master/src/utils/auto-correct-misspellings.ts)',
223+
'description': '通过常见拼写错误字典自动将错误拼写更正为正确拼写。有关自动更正单词的完整列表,请参阅 [auto-correct map](https://github.com/platers/obsidian-linter/tree/master/src/utils/default-misspellings.md)',
224224
'ignore-words': {
225225
'name': '忽略单词',
226226
'description': '以逗号分隔的小写单词列表,在自动更正时会忽略',

0 commit comments

Comments
 (0)