@spyglassmc/core 0.1.0

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.
Files changed (186) hide show
  1. package/README.md +10 -0
  2. package/lib/common/Heap.d.ts +1 -0
  3. package/lib/common/Heap.js +2 -0
  4. package/lib/common/index.d.ts +2 -0
  5. package/lib/common/index.js +14 -0
  6. package/lib/common/util.d.ts +120 -0
  7. package/lib/common/util.js +292 -0
  8. package/lib/index.d.ts +8 -0
  9. package/lib/index.js +20 -0
  10. package/lib/node/AstNode.d.ts +64 -0
  11. package/lib/node/AstNode.js +108 -0
  12. package/lib/node/BooleanNode.d.ts +13 -0
  13. package/lib/node/BooleanNode.js +20 -0
  14. package/lib/node/CommentNode.d.ts +12 -0
  15. package/lib/node/CommentNode.js +11 -0
  16. package/lib/node/ErrorNode.d.ts +8 -0
  17. package/lib/node/ErrorNode.js +12 -0
  18. package/lib/node/FileNode.d.ts +21 -0
  19. package/lib/node/FileNode.js +11 -0
  20. package/lib/node/FloatNode.d.ts +13 -0
  21. package/lib/node/FloatNode.js +21 -0
  22. package/lib/node/IntegerNode.d.ts +13 -0
  23. package/lib/node/IntegerNode.js +20 -0
  24. package/lib/node/ListNode.d.ts +15 -0
  25. package/lib/node/ListNode.js +11 -0
  26. package/lib/node/LiteralNode.d.ts +19 -0
  27. package/lib/node/LiteralNode.js +22 -0
  28. package/lib/node/LongNode.d.ts +13 -0
  29. package/lib/node/LongNode.js +20 -0
  30. package/lib/node/RecordNode.d.ts +20 -0
  31. package/lib/node/RecordNode.js +11 -0
  32. package/lib/node/ResourceLocationNode.d.ts +41 -0
  33. package/lib/node/ResourceLocationNode.js +65 -0
  34. package/lib/node/Sequence.d.ts +22 -0
  35. package/lib/node/Sequence.js +11 -0
  36. package/lib/node/StringNode.d.ts +63 -0
  37. package/lib/node/StringNode.js +43 -0
  38. package/lib/node/SymbolNode.d.ts +21 -0
  39. package/lib/node/SymbolNode.js +22 -0
  40. package/lib/node/TableNode.d.ts +17 -0
  41. package/lib/node/TableNode.js +11 -0
  42. package/lib/node/index.d.ts +16 -0
  43. package/lib/node/index.js +28 -0
  44. package/lib/parser/Parser.d.ts +16 -0
  45. package/lib/parser/Parser.js +5 -0
  46. package/lib/parser/boolean.d.ts +4 -0
  47. package/lib/parser/boolean.js +11 -0
  48. package/lib/parser/comment.d.ts +12 -0
  49. package/lib/parser/comment.js +34 -0
  50. package/lib/parser/empty.d.ts +3 -0
  51. package/lib/parser/empty.js +7 -0
  52. package/lib/parser/error.d.ts +8 -0
  53. package/lib/parser/error.js +22 -0
  54. package/lib/parser/file.d.ts +9 -0
  55. package/lib/parser/file.js +37 -0
  56. package/lib/parser/float.d.ts +33 -0
  57. package/lib/parser/float.js +57 -0
  58. package/lib/parser/index.d.ts +17 -0
  59. package/lib/parser/index.js +36 -0
  60. package/lib/parser/integer.d.ts +33 -0
  61. package/lib/parser/integer.js +46 -0
  62. package/lib/parser/list.d.ts +12 -0
  63. package/lib/parser/list.js +70 -0
  64. package/lib/parser/literal.d.ts +5 -0
  65. package/lib/parser/literal.js +41 -0
  66. package/lib/parser/long.d.ts +33 -0
  67. package/lib/parser/long.js +50 -0
  68. package/lib/parser/record.d.ts +22 -0
  69. package/lib/parser/record.js +97 -0
  70. package/lib/parser/resourceLocation.d.ts +4 -0
  71. package/lib/parser/resourceLocation.js +67 -0
  72. package/lib/parser/string.d.ts +18 -0
  73. package/lib/parser/string.js +129 -0
  74. package/lib/parser/symbol.d.ts +12 -0
  75. package/lib/parser/symbol.js +33 -0
  76. package/lib/parser/table.d.ts +22 -0
  77. package/lib/parser/table.js +97 -0
  78. package/lib/parser/util.d.ts +134 -0
  79. package/lib/parser/util.js +224 -0
  80. package/lib/processor/ColorInfoProvider.d.ts +87 -0
  81. package/lib/processor/ColorInfoProvider.js +141 -0
  82. package/lib/processor/InlayHintProvider.d.ts +8 -0
  83. package/lib/processor/InlayHintProvider.js +3 -0
  84. package/lib/processor/SignatureHelpProvider.d.ts +18 -0
  85. package/lib/processor/SignatureHelpProvider.js +3 -0
  86. package/lib/processor/checker/Checker.d.ts +7 -0
  87. package/lib/processor/checker/Checker.js +7 -0
  88. package/lib/processor/checker/builtin.d.ts +23 -0
  89. package/lib/processor/checker/builtin.js +83 -0
  90. package/lib/processor/checker/index.d.ts +3 -0
  91. package/lib/processor/checker/index.js +28 -0
  92. package/lib/processor/colorizer/Colorizer.d.ts +23 -0
  93. package/lib/processor/colorizer/Colorizer.js +70 -0
  94. package/lib/processor/colorizer/builtin.d.ts +17 -0
  95. package/lib/processor/colorizer/builtin.js +84 -0
  96. package/lib/processor/colorizer/index.d.ts +3 -0
  97. package/lib/processor/colorizer/index.js +28 -0
  98. package/lib/processor/completer/Completer.d.ts +75 -0
  99. package/lib/processor/completer/Completer.js +92 -0
  100. package/lib/processor/completer/builtin.d.ts +30 -0
  101. package/lib/processor/completer/builtin.js +172 -0
  102. package/lib/processor/completer/index.d.ts +3 -0
  103. package/lib/processor/completer/index.js +28 -0
  104. package/lib/processor/formatter/Formatter.d.ts +6 -0
  105. package/lib/processor/formatter/Formatter.js +19 -0
  106. package/lib/processor/formatter/builtin.d.ts +15 -0
  107. package/lib/processor/formatter/builtin.js +60 -0
  108. package/lib/processor/formatter/index.d.ts +3 -0
  109. package/lib/processor/formatter/index.js +28 -0
  110. package/lib/processor/index.d.ts +10 -0
  111. package/lib/processor/index.js +22 -0
  112. package/lib/processor/linter/Linter.d.ts +4 -0
  113. package/lib/processor/linter/Linter.js +3 -0
  114. package/lib/processor/linter/builtin/undeclaredSymbol.d.ts +4 -0
  115. package/lib/processor/linter/builtin/undeclaredSymbol.js +73 -0
  116. package/lib/processor/linter/builtin.d.ts +15 -0
  117. package/lib/processor/linter/builtin.js +120 -0
  118. package/lib/processor/linter/index.d.ts +3 -0
  119. package/lib/processor/linter/index.js +28 -0
  120. package/lib/processor/util.d.ts +17 -0
  121. package/lib/processor/util.js +32 -0
  122. package/lib/service/CacheService.d.ts +54 -0
  123. package/lib/service/CacheService.js +195 -0
  124. package/lib/service/CommandExecutor.d.ts +3 -0
  125. package/lib/service/CommandExecutor.js +7 -0
  126. package/lib/service/Config.d.ts +218 -0
  127. package/lib/service/Config.js +264 -0
  128. package/lib/service/Context.d.ts +143 -0
  129. package/lib/service/Context.js +143 -0
  130. package/lib/service/Dependency.d.ts +10 -0
  131. package/lib/service/Dependency.js +11 -0
  132. package/lib/service/Downloader.d.ts +67 -0
  133. package/lib/service/Downloader.js +185 -0
  134. package/lib/service/ErrorReporter.d.ts +27 -0
  135. package/lib/service/ErrorReporter.js +49 -0
  136. package/lib/service/FileService.d.ts +96 -0
  137. package/lib/service/FileService.js +224 -0
  138. package/lib/service/Hover.d.ts +10 -0
  139. package/lib/service/Hover.js +16 -0
  140. package/lib/service/Logger.d.ts +31 -0
  141. package/lib/service/Logger.js +30 -0
  142. package/lib/service/MetaRegistry.d.ts +106 -0
  143. package/lib/service/MetaRegistry.js +192 -0
  144. package/lib/service/Operations.d.ts +8 -0
  145. package/lib/service/Operations.js +26 -0
  146. package/lib/service/Profiler.d.ts +33 -0
  147. package/lib/service/Profiler.js +76 -0
  148. package/lib/service/Project.d.ts +173 -0
  149. package/lib/service/Project.js +593 -0
  150. package/lib/service/Service.d.ts +55 -0
  151. package/lib/service/Service.js +207 -0
  152. package/lib/service/SymbolLocations.d.ts +17 -0
  153. package/lib/service/SymbolLocations.js +16 -0
  154. package/lib/service/SymbolRegistrar.d.ts +5 -0
  155. package/lib/service/SymbolRegistrar.js +3 -0
  156. package/lib/service/fileUtil.d.ts +121 -0
  157. package/lib/service/fileUtil.js +268 -0
  158. package/lib/service/index.d.ts +18 -0
  159. package/lib/service/index.js +33 -0
  160. package/lib/source/IndexMap.d.ts +16 -0
  161. package/lib/source/IndexMap.js +46 -0
  162. package/lib/source/LanguageError.d.ts +27 -0
  163. package/lib/source/LanguageError.js +15 -0
  164. package/lib/source/Location.d.ts +19 -0
  165. package/lib/source/Location.js +25 -0
  166. package/lib/source/Offset.d.ts +13 -0
  167. package/lib/source/Offset.js +25 -0
  168. package/lib/source/Position.d.ts +23 -0
  169. package/lib/source/Position.js +43 -0
  170. package/lib/source/PositionRange.d.ts +38 -0
  171. package/lib/source/PositionRange.js +83 -0
  172. package/lib/source/Range.d.ts +68 -0
  173. package/lib/source/Range.js +155 -0
  174. package/lib/source/Source.d.ts +110 -0
  175. package/lib/source/Source.js +222 -0
  176. package/lib/source/index.d.ts +9 -0
  177. package/lib/source/index.js +21 -0
  178. package/lib/symbol/Symbol.d.ts +219 -0
  179. package/lib/symbol/Symbol.js +324 -0
  180. package/lib/symbol/SymbolUtil.d.ts +407 -0
  181. package/lib/symbol/SymbolUtil.js +880 -0
  182. package/lib/symbol/UriBinder.d.ts +3 -0
  183. package/lib/symbol/UriBinder.js +3 -0
  184. package/lib/symbol/index.d.ts +4 -0
  185. package/lib/symbol/index.js +16 -0
  186. package/package.json +41 -0
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerFormatters = exports.string = exports.resourceLocation = exports.long = exports.literal = exports.integer = exports.float = exports.comment = exports.boolean = exports.file = exports.fallback = void 0;
4
+ const node_1 = require("../../node");
5
+ const fallback = node => {
6
+ throw new Error(`No formatter registered for type ${node.type}`);
7
+ };
8
+ exports.fallback = fallback;
9
+ const file = (node, ctx) => {
10
+ return node.children.map(child => {
11
+ return ctx.meta.getFormatter(child.type)(child, ctx);
12
+ }).join('');
13
+ };
14
+ exports.file = file;
15
+ const boolean = node => {
16
+ return node.value ? 'true' : 'false';
17
+ };
18
+ exports.boolean = boolean;
19
+ const comment = node => {
20
+ return '#' + node.comment;
21
+ };
22
+ exports.comment = comment;
23
+ const float = node => {
24
+ return node.value.toString();
25
+ };
26
+ exports.float = float;
27
+ const integer = node => {
28
+ return node.value.toFixed();
29
+ };
30
+ exports.integer = integer;
31
+ const literal = node => {
32
+ return node.value;
33
+ };
34
+ exports.literal = literal;
35
+ const long = node => {
36
+ return node.value.toString();
37
+ };
38
+ exports.long = long;
39
+ const resourceLocation = node => {
40
+ return node_1.ResourceLocationNode.toString(node, 'origin');
41
+ };
42
+ exports.resourceLocation = resourceLocation;
43
+ const string = node => {
44
+ // FIXME: escape this value according to the node's IndexMap and context
45
+ return `"${node.value}"`;
46
+ };
47
+ exports.string = string;
48
+ function registerFormatters(meta) {
49
+ meta.registerFormatter('file', exports.file);
50
+ meta.registerFormatter('boolean', exports.boolean);
51
+ meta.registerFormatter('comment', exports.comment);
52
+ meta.registerFormatter('float', exports.float);
53
+ meta.registerFormatter('integer', exports.integer);
54
+ meta.registerFormatter('long', exports.long);
55
+ meta.registerFormatter('literal', exports.literal);
56
+ meta.registerFormatter('resource_location', exports.resourceLocation);
57
+ meta.registerFormatter('string', exports.string);
58
+ }
59
+ exports.registerFormatters = registerFormatters;
60
+ //# sourceMappingURL=builtin.js.map
@@ -0,0 +1,3 @@
1
+ export * as formatter from './builtin';
2
+ export * from './Formatter';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
22
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.formatter = void 0;
26
+ exports.formatter = __importStar(require("./builtin"));
27
+ __exportStar(require("./Formatter"), exports);
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,10 @@
1
+ export * from './checker';
2
+ export * from './ColorInfoProvider';
3
+ export * from './colorizer';
4
+ export * from './completer';
5
+ export * from './formatter';
6
+ export * from './InlayHintProvider';
7
+ export * from './linter';
8
+ export * from './SignatureHelpProvider';
9
+ export * from './util';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./checker"), exports);
14
+ __exportStar(require("./ColorInfoProvider"), exports);
15
+ __exportStar(require("./colorizer"), exports);
16
+ __exportStar(require("./completer"), exports);
17
+ __exportStar(require("./formatter"), exports);
18
+ __exportStar(require("./InlayHintProvider"), exports);
19
+ __exportStar(require("./linter"), exports);
20
+ __exportStar(require("./SignatureHelpProvider"), exports);
21
+ __exportStar(require("./util"), exports);
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,4 @@
1
+ import type { AstNode } from '../../node';
2
+ import type { LinterContext } from '../../service';
3
+ export declare type Linter<N extends AstNode> = (node: N, ctx: LinterContext) => void;
4
+ //# sourceMappingURL=Linter.d.ts.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=Linter.js.map
@@ -0,0 +1,4 @@
1
+ import type { AstNode } from '../../../node';
2
+ import type { Linter } from '../Linter';
3
+ export declare const undeclaredSymbol: Linter<AstNode>;
4
+ //# sourceMappingURL=undeclaredSymbol.d.ts.map
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.undeclaredSymbol = void 0;
4
+ const locales_1 = require("@spyglassmc/locales");
5
+ const common_1 = require("../../../common");
6
+ const service_1 = require("../../../service");
7
+ const symbol_1 = require("../../../symbol");
8
+ const undeclaredSymbol = (node, ctx) => {
9
+ if (!node.symbol || symbol_1.SymbolUtil.isDeclared(node.symbol)) {
10
+ return;
11
+ }
12
+ const action = getAction(ctx.ruleValue, node.symbol, ctx);
13
+ if (service_1.SymbolLinterConfig.Action.isDeclare(action)) {
14
+ ctx.symbols
15
+ .query({ doc: ctx.doc, node }, node.symbol.category, ...node.symbol.path)
16
+ .amend({
17
+ data: { visibility: getVisibility(action.declare) },
18
+ usage: { type: 'declaration', node },
19
+ });
20
+ }
21
+ if (service_1.SymbolLinterConfig.Action.isReport(action)) {
22
+ const severityOverride = action.report === 'inherit' ? undefined : service_1.LinterSeverity.toErrorSeverity(action.report);
23
+ ctx.err.lint((0, locales_1.localize)('linter.undeclared-symbol.message', node.symbol.category, (0, locales_1.localeQuote)(node.symbol.identifier)), node, undefined, severityOverride);
24
+ }
25
+ };
26
+ exports.undeclaredSymbol = undeclaredSymbol;
27
+ function getAction(config, symbol, ctx) {
28
+ if (service_1.SymbolLinterConfig.Action.is(config)) {
29
+ return config;
30
+ }
31
+ function test(conditions) {
32
+ function testSingleCondition(condition) {
33
+ const resourceLocation = common_1.ResourceLocation.lengthen(symbol.identifier);
34
+ const namespace = resourceLocation.slice(0, resourceLocation.indexOf(common_1.ResourceLocation.NamespacePathSep));
35
+ return ((condition.category ? common_1.Arrayable.toArray(condition.category).includes(symbol.category) : true) &&
36
+ (condition.namespace ? common_1.Arrayable.toArray(condition.namespace).includes(namespace) : true) &&
37
+ (condition.excludeNamespace ? !common_1.Arrayable.toArray(condition.excludeNamespace).includes(namespace) : true) &&
38
+ (condition.pattern ? common_1.Arrayable.toArray(condition.pattern).some(p => new RegExp(p).test(symbol.identifier)) : true) &&
39
+ (condition.excludePattern ? !common_1.Arrayable.toArray(condition.excludePattern).some(p => new RegExp(p).test(symbol.identifier)) : true));
40
+ }
41
+ try {
42
+ return common_1.Arrayable.toArray(conditions).some(testSingleCondition);
43
+ }
44
+ catch (e) {
45
+ // Illegal RegExp.
46
+ ctx.logger.error('[undeclaredSymbol#getAction] Likely encountered an illegal regular expression in the config', e);
47
+ return false;
48
+ }
49
+ }
50
+ function evaluateComplexes(complexes) {
51
+ for (const complex of common_1.Arrayable.toArray(complexes)) {
52
+ if (complex.if && !test(complex.if)) {
53
+ continue;
54
+ }
55
+ return complex.override
56
+ ? evaluateComplexes(complex.override) ?? complex.then
57
+ : complex.then;
58
+ }
59
+ return undefined;
60
+ }
61
+ return evaluateComplexes(config);
62
+ }
63
+ function getVisibility(input) {
64
+ switch (input) {
65
+ case 'block':
66
+ return 0 /* Block */;
67
+ case 'file':
68
+ return 1 /* File */;
69
+ case 'public':
70
+ return 2 /* Public */;
71
+ }
72
+ }
73
+ //# sourceMappingURL=undeclaredSymbol.js.map
@@ -0,0 +1,15 @@
1
+ import type { AstNode, StringBaseNode } from '../../node';
2
+ import type { Logger, MetaRegistry } from '../../service';
3
+ import type { Linter } from './Linter';
4
+ export declare const noop: Linter<AstNode>;
5
+ /**
6
+ * @param key The name of the key on the {@link AstNode} that contains the value to be validated.
7
+ */
8
+ export declare function nameConvention(key: string): Linter<AstNode>;
9
+ export declare const quote: Linter<StringBaseNode>;
10
+ export declare namespace configValidator {
11
+ function nameConvention(name: string, val: unknown, logger: Logger): boolean;
12
+ function symbolLinterConfig(_name: string, value: unknown, _logger: Logger): boolean;
13
+ }
14
+ export declare function registerLinters(meta: MetaRegistry): void;
15
+ //# sourceMappingURL=builtin.d.ts.map
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerLinters = exports.configValidator = exports.quote = exports.nameConvention = exports.noop = void 0;
4
+ const locales_1 = require("@spyglassmc/locales");
5
+ const parser_1 = require("../../parser");
6
+ const service_1 = require("../../service");
7
+ const symbol_1 = require("../../symbol");
8
+ const undeclaredSymbol_1 = require("./builtin/undeclaredSymbol");
9
+ const noop = () => { };
10
+ exports.noop = noop;
11
+ /**
12
+ * @param key The name of the key on the {@link AstNode} that contains the value to be validated.
13
+ */
14
+ function nameConvention(key) {
15
+ return (node, ctx) => {
16
+ if (typeof node[key] !== 'string') {
17
+ throw new Error(`Trying to access property "${key}" of node type "${node.type}"`);
18
+ }
19
+ const name = node[key];
20
+ try {
21
+ // SECURITY: ReDoS attack. The risk is acceptable at the moment.
22
+ const regex = new RegExp(ctx.ruleValue);
23
+ if (!name.match(regex)) {
24
+ ctx.err.lint((0, locales_1.localize)('linter.name-convention.illegal', (0, locales_1.localeQuote)(name), (0, locales_1.localeQuote)(ctx.ruleValue)), node);
25
+ }
26
+ }
27
+ catch (e) {
28
+ ctx.logger.error(`[nameConvention linter] The value “${ctx.ruleValue}” set for rule “${ctx.ruleName}” is not a valid regular expression.`, e);
29
+ }
30
+ };
31
+ }
32
+ exports.nameConvention = nameConvention;
33
+ const quote = (node, ctx) => {
34
+ const config = ctx.ruleValue;
35
+ const mustValueBeQuoted = node.options.unquotable
36
+ ? [...node.value].some(c => !(0, parser_1.isAllowedCharacter)(c, node.options.unquotable))
37
+ : true;
38
+ const isQuoteRequired = config.always || mustValueBeQuoted;
39
+ const isQuoteProhibited = config.always === false && !mustValueBeQuoted;
40
+ const firstChar = ctx.src.slice(node.range.start, node.range.start + 1);
41
+ const isFirstCharQuote = !!node.options.quotes?.includes(firstChar);
42
+ if (isQuoteRequired) {
43
+ if (isFirstCharQuote) {
44
+ // TODO: Check type
45
+ config.avoidEscape;
46
+ config.type;
47
+ }
48
+ else {
49
+ // TODO: Error quote expected
50
+ }
51
+ }
52
+ else if (isQuoteProhibited && isFirstCharQuote) {
53
+ // TODO: Error no quote expected
54
+ }
55
+ };
56
+ exports.quote = quote;
57
+ var configValidator;
58
+ (function (configValidator) {
59
+ function getDocLink(name) {
60
+ return `https://spyglassmc.com/user/lint/${name}`;
61
+ }
62
+ function wrapError(name, msg) {
63
+ return `[Invalid Linter Config] [${name}] ${(0, locales_1.localize)('linter-config-validator.wrapper', msg, getDocLink(name))}`;
64
+ }
65
+ function nameConvention(name, val, logger) {
66
+ if (typeof val !== 'string') {
67
+ logger.error(wrapError(name, (0, locales_1.localize)('linter-config-validator.name-convention.type')));
68
+ return false;
69
+ }
70
+ try {
71
+ // SECURITY: ReDoS attack. The risk is acceptable at the moment.
72
+ new RegExp(val);
73
+ }
74
+ catch (e) {
75
+ logger.error(wrapError(name, (0, locales_1.localize)('') // FIXME
76
+ ), e);
77
+ return false;
78
+ }
79
+ return true;
80
+ }
81
+ configValidator.nameConvention = nameConvention;
82
+ function symbolLinterConfig(_name, value, _logger) {
83
+ return service_1.SymbolLinterConfig.is(value);
84
+ }
85
+ configValidator.symbolLinterConfig = symbolLinterConfig;
86
+ })(configValidator = exports.configValidator || (exports.configValidator = {}));
87
+ function registerLinters(meta) {
88
+ meta.registerLinter('nameOfNbtKey', {
89
+ configValidator: configValidator.nameConvention,
90
+ linter: nameConvention('value'),
91
+ nodePredicate: n => n.parent?.parent?.type === 'nbt:compound' && n.parent.type === 'pair' && n.type === 'string',
92
+ });
93
+ meta.registerLinter('nameOfObjective', {
94
+ configValidator: configValidator.nameConvention,
95
+ linter: nameConvention('value'),
96
+ nodePredicate: n => n.symbol && n.symbol.category === 'objective',
97
+ });
98
+ meta.registerLinter('nameOfScoreHolder', {
99
+ configValidator: configValidator.nameConvention,
100
+ linter: nameConvention('value'),
101
+ nodePredicate: n => n.symbol && n.symbol.category === 'score_holder',
102
+ });
103
+ meta.registerLinter('nameOfTag', {
104
+ configValidator: configValidator.nameConvention,
105
+ linter: nameConvention('value'),
106
+ nodePredicate: n => n.symbol && n.symbol.category === 'tag',
107
+ });
108
+ meta.registerLinter('nameOfTeam', {
109
+ configValidator: configValidator.nameConvention,
110
+ linter: nameConvention('value'),
111
+ nodePredicate: n => n.symbol && n.symbol.category === 'team',
112
+ });
113
+ meta.registerLinter('undeclaredSymbol', {
114
+ configValidator: configValidator.symbolLinterConfig,
115
+ linter: undeclaredSymbol_1.undeclaredSymbol,
116
+ nodePredicate: n => n.symbol && !symbol_1.NbtdocCategories.includes(n.symbol.category),
117
+ });
118
+ }
119
+ exports.registerLinters = registerLinters;
120
+ //# sourceMappingURL=builtin.js.map
@@ -0,0 +1,3 @@
1
+ export * as linter from './builtin';
2
+ export * from './Linter';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
22
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.linter = void 0;
26
+ exports.linter = __importStar(require("./builtin"));
27
+ __exportStar(require("./Linter"), exports);
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,17 @@
1
+ import type { AstNode } from '../node';
2
+ import { Range } from '../source';
3
+ declare type Callback<R> = (this: void, node: AstNode, parents: AstNode[]) => R;
4
+ export declare function traversePreOrder(node: AstNode, shouldContinue: Callback<unknown>, shouldCallFn: Callback<unknown>, fn: Callback<unknown>): void;
5
+ interface NodeResult {
6
+ node: AstNode | undefined;
7
+ /**
8
+ * Ordered from the closest parent to the root node.
9
+ */
10
+ parents: AstNode[];
11
+ }
12
+ /**
13
+ * @returns The shallowest node that is fully contained within `range`.
14
+ */
15
+ export declare function findNode(node: AstNode, range: Range): NodeResult;
16
+ export {};
17
+ //# sourceMappingURL=util.d.ts.map
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findNode = exports.traversePreOrder = void 0;
4
+ const source_1 = require("../source");
5
+ function traversePreOrder(node, shouldContinue, shouldCallFn, fn) {
6
+ traversePreOrderImpl(node, shouldContinue, shouldCallFn, fn, []);
7
+ }
8
+ exports.traversePreOrder = traversePreOrder;
9
+ function traversePreOrderImpl(node, shouldContinue, shouldCallFn, fn, parents) {
10
+ if (shouldCallFn(node, parents)) {
11
+ fn(node, parents);
12
+ }
13
+ if (!node.children || !shouldContinue(node, parents)) {
14
+ return;
15
+ }
16
+ for (const child of node.children ?? []) {
17
+ parents.unshift(node);
18
+ traversePreOrderImpl(child, shouldContinue, shouldCallFn, fn, parents);
19
+ parents.shift();
20
+ }
21
+ }
22
+ /**
23
+ * @returns The shallowest node that is fully contained within `range`.
24
+ */
25
+ function findNode(node, range) {
26
+ let ans = { node: undefined, parents: [] };
27
+ // TODO: Binary search here.
28
+ traversePreOrder(node, (node) => ans.node === undefined && source_1.Range.intersects(node.range, range), (node) => source_1.Range.containsRange(range, node.range), (node, parents) => ans = { node, parents: [...parents] });
29
+ return ans;
30
+ }
31
+ exports.findNode = findNode;
32
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1,54 @@
1
+ import { SymbolTable } from '../symbol';
2
+ import type { RootUriString } from './fileUtil';
3
+ import type { Project } from './Project';
4
+ /**
5
+ * The format version of the cache. Should be increased when any changes that
6
+ * could invalidate the cache are introduced to the Spyglass codebase.
7
+ */
8
+ export declare const LatestCacheVersion = 1;
9
+ /**
10
+ * Checksums of cached files or roots.
11
+ */
12
+ interface Checksums {
13
+ files: Record<string, string>;
14
+ roots: Record<RootUriString, string>;
15
+ symbolRegistrars: Record<string, string>;
16
+ }
17
+ declare namespace Checksums {
18
+ function create(): Checksums;
19
+ }
20
+ interface LoadResult {
21
+ symbols: SymbolTable;
22
+ }
23
+ interface ValidateResult {
24
+ addedFiles: string[];
25
+ changedFiles: string[];
26
+ removedFiles: string[];
27
+ unchangedFiles: string[];
28
+ }
29
+ export declare class CacheService {
30
+ #private;
31
+ private readonly cacheRoot;
32
+ private readonly project;
33
+ checksums: Checksums;
34
+ /**
35
+ * @param cacheRoot File path to the directory where cache files by Spyglass should be stored.
36
+ * @param project
37
+ */
38
+ constructor(cacheRoot: string, project: Project);
39
+ /**
40
+ * @throws
41
+ *
42
+ * @returns `${cacheRoot}/symbols/${sha1(projectRoot)}.json`
43
+ */
44
+ private getCacheFilePath;
45
+ load(): Promise<LoadResult>;
46
+ validate(): Promise<ValidateResult>;
47
+ /**
48
+ * @returns If the cache file was saved successfully.
49
+ */
50
+ save(): Promise<boolean>;
51
+ reset(): void;
52
+ }
53
+ export {};
54
+ //# sourceMappingURL=CacheService.d.ts.map