@cspell/eslint-plugin 5.19.2 → 5.19.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,10 +1,16 @@
1
- # [WIP] CSpell ESLint Plugin
1
+ # CSpell ESLint Plugin
2
2
 
3
3
  A spell checker plugin for ESLint based upon CSpell.
4
4
 
5
- ## [WIP] - Work In Progress
5
+ ## Feedback Welcome
6
6
 
7
- This plugin is still in active development. Due to the nature of how files are parsed, the `cspell` command line tool and this ESLint plugin will give different results. It is recommended that ESLint or `cspell` checks a file, but not both. Use `ignorePaths` setting in `cspell.json` to tell the `cspell` command line tool to ignore files checked by ESLint.
7
+ This plugin is still in active development as part of the CSpell suite of tools and applications.
8
+
9
+ ## In Combination with CSpell
10
+
11
+ Due to the nature of how files are parsed, the `cspell` command line tool and this ESLint plugin will give different results.
12
+ It is recommended that either ESLint or `cspell` checks a file, but not both. Use `ignorePaths` setting in `cspell.json` to
13
+ tell the `cspell` command line tool to ignore files checked by ESLint.
8
14
 
9
15
  ## Quick Setup
10
16
 
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @cspell/eslint-plugin v5.19.1
2
+ * @cspell/eslint-plugin v5.19.4
3
3
  * Copyright 2022 Jason Dent <jason@streetsidesoftware.nl>
4
4
  * Released under the MIT License
5
5
  * https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell-eslint-plugin#readme
@@ -139,8 +139,7 @@ function create(context) {
139
139
  const importedIdentifiers = new Set();
140
140
  isDebugMode = options.debugMode || false;
141
141
  isDebugMode && logContext(context);
142
- const doc = cspellLib.createTextDocument({ uri: context.getFilename(), content: context.getSourceCode().getText() });
143
- const validator = new cspellLib.DocumentValidator(doc, options, defaultSettings);
142
+ const validator = getDocValidator(context);
144
143
  validator.prepareSync();
145
144
  function checkLiteral(node) {
146
145
  if (!options.checkStrings)
@@ -430,6 +429,33 @@ const configs = {
430
429
  },
431
430
  },
432
431
  };
432
+ const cache = { lastDoc: undefined };
433
+ const docValCache = new WeakMap();
434
+ function getDocValidator(context) {
435
+ const text = context.getSourceCode().getText();
436
+ const doc = getTextDocument(context.getFilename(), text);
437
+ const cachedValidator = docValCache.get(doc);
438
+ if (cachedValidator) {
439
+ cachedValidator.updateDocumentText(text);
440
+ return cachedValidator;
441
+ }
442
+ const options = normalizeOptions(context.options[0]);
443
+ isDebugMode = options.debugMode || false;
444
+ isDebugMode && logContext(context);
445
+ const validator = new cspellLib.DocumentValidator(doc, options, defaultSettings);
446
+ docValCache.set(doc, validator);
447
+ return validator;
448
+ }
449
+ function getTextDocument(filename, content) {
450
+ var _a;
451
+ if (((_a = cache.lastDoc) === null || _a === void 0 ? void 0 : _a.filename) === filename) {
452
+ return cache.lastDoc.doc;
453
+ }
454
+ const doc = cspellLib.createTextDocument({ uri: filename, content });
455
+ // console.error(`CreateTextDocument: ${doc.uri}`);
456
+ cache.lastDoc = { filename, doc };
457
+ return doc;
458
+ }
433
459
 
434
460
  exports.configs = configs;
435
461
  exports.rules = rules;
package/dist/index.mjs CHANGED
@@ -1,12 +1,12 @@
1
1
  /*!
2
- * @cspell/eslint-plugin v5.19.1
2
+ * @cspell/eslint-plugin v5.19.4
3
3
  * Copyright 2022 Jason Dent <jason@streetsidesoftware.nl>
4
4
  * Released under the MIT License
5
5
  * https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell-eslint-plugin#readme
6
6
  */
7
7
 
8
8
  import assert from 'assert';
9
- import { createTextDocument, DocumentValidator } from 'cspell-lib';
9
+ import { DocumentValidator, createTextDocument } from 'cspell-lib';
10
10
  import { format } from 'util';
11
11
 
12
12
  const defaultCheckOptions = {
@@ -131,8 +131,7 @@ function create(context) {
131
131
  const importedIdentifiers = new Set();
132
132
  isDebugMode = options.debugMode || false;
133
133
  isDebugMode && logContext(context);
134
- const doc = createTextDocument({ uri: context.getFilename(), content: context.getSourceCode().getText() });
135
- const validator = new DocumentValidator(doc, options, defaultSettings);
134
+ const validator = getDocValidator(context);
136
135
  validator.prepareSync();
137
136
  function checkLiteral(node) {
138
137
  if (!options.checkStrings)
@@ -422,6 +421,33 @@ const configs = {
422
421
  },
423
422
  },
424
423
  };
424
+ const cache = { lastDoc: undefined };
425
+ const docValCache = new WeakMap();
426
+ function getDocValidator(context) {
427
+ const text = context.getSourceCode().getText();
428
+ const doc = getTextDocument(context.getFilename(), text);
429
+ const cachedValidator = docValCache.get(doc);
430
+ if (cachedValidator) {
431
+ cachedValidator.updateDocumentText(text);
432
+ return cachedValidator;
433
+ }
434
+ const options = normalizeOptions(context.options[0]);
435
+ isDebugMode = options.debugMode || false;
436
+ isDebugMode && logContext(context);
437
+ const validator = new DocumentValidator(doc, options, defaultSettings);
438
+ docValCache.set(doc, validator);
439
+ return validator;
440
+ }
441
+ function getTextDocument(filename, content) {
442
+ var _a;
443
+ if (((_a = cache.lastDoc) === null || _a === void 0 ? void 0 : _a.filename) === filename) {
444
+ return cache.lastDoc.doc;
445
+ }
446
+ const doc = createTextDocument({ uri: filename, content });
447
+ // console.error(`CreateTextDocument: ${doc.uri}`);
448
+ cache.lastDoc = { filename, doc };
449
+ return doc;
450
+ }
425
451
 
426
452
  export { configs, rules };
427
453
  //# sourceMappingURL=index.mjs.map
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "5.19.2",
6
+ "version": "5.19.5",
7
7
  "description": "[WIP] CSpell ESLint plugin",
8
8
  "keywords": [
9
9
  "cspell",
@@ -54,25 +54,25 @@
54
54
  "node": ">=12.13.0"
55
55
  },
56
56
  "devDependencies": {
57
- "@rollup/plugin-commonjs": "^21.0.2",
57
+ "@rollup/plugin-commonjs": "^21.0.3",
58
58
  "@rollup/plugin-json": "^4.1.0",
59
59
  "@rollup/plugin-node-resolve": "^13.1.3",
60
60
  "@rollup/plugin-typescript": "^8.3.1",
61
61
  "@types/eslint": "^8.4.1",
62
62
  "@types/estree": "^0.0.51",
63
- "@types/node": "^17.0.21",
64
- "@typescript-eslint/parser": "^5.14.0",
65
- "@typescript-eslint/types": "^5.14.0",
66
- "@typescript-eslint/typescript-estree": "^5.14.0",
67
- "eslint": "^8.11.0",
63
+ "@types/node": "^17.0.23",
64
+ "@typescript-eslint/parser": "^5.17.0",
65
+ "@typescript-eslint/types": "^5.17.0",
66
+ "@typescript-eslint/typescript-estree": "^5.17.0",
67
+ "eslint": "^8.12.0",
68
68
  "mocha": "^9.2.2",
69
69
  "rimraf": "^3.0.2",
70
- "rollup": "^2.70.0",
70
+ "rollup": "^2.70.1",
71
71
  "rollup-plugin-dts": "^4.2.0",
72
- "ts-json-schema-generator": "^0.98.0"
72
+ "ts-json-schema-generator": "^1.0.0"
73
73
  },
74
74
  "dependencies": {
75
- "cspell-lib": "^5.19.2"
75
+ "cspell-lib": "^5.19.5"
76
76
  },
77
- "gitHead": "6540cb9f716993c554dc50dd54dd76d553f8f5e4"
77
+ "gitHead": "0d113f01b51c3bc149a01269878d4217a58ecb97"
78
78
  }