ilib-lint 2.2.0 → 2.3.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 (97) hide show
  1. package/docs/AnsiConsoleFormatter.html +2 -2
  2. package/docs/BuiltinPlugin.html +2 -2
  3. package/docs/ConfigBasedFormatter.html +2 -2
  4. package/docs/ConfigurationProvider.html +3 -3
  5. package/docs/ConfigurationProvider_loadConfiguration.html +3 -3
  6. package/docs/DeclarativeResourceRule.html +2 -2
  7. package/docs/DirItem.html +2 -2
  8. package/docs/DirItem.js.html +2 -2
  9. package/docs/FileConfigurationProvider.html +5 -5
  10. package/docs/FileConfigurationProvider_loadConfiguration.html +3 -3
  11. package/docs/FileType.html +181 -5
  12. package/docs/FileType.js.html +48 -5
  13. package/docs/FixerManager.html +2 -2
  14. package/docs/FixerManager.js.html +4 -4
  15. package/docs/FolderConfigurationProvider.html +4 -4
  16. package/docs/FolderConfigurationProvider_loadConfiguration.html +3 -3
  17. package/docs/FormatterManager.html +2 -2
  18. package/docs/FormatterManager.js.html +5 -5
  19. package/docs/LineParser.html +78 -4
  20. package/docs/LineRegexpChecker.html +2 -2
  21. package/docs/LintableFile.html +1099 -0
  22. package/docs/LintableFile.js.html +330 -0
  23. package/docs/ParserManager.html +167 -5
  24. package/docs/ParserManager.js.html +17 -5
  25. package/docs/PluginManager.html +10 -10
  26. package/docs/PluginManager.js.html +120 -92
  27. package/docs/Project.html +24 -24
  28. package/docs/Project.js.html +125 -88
  29. package/docs/ReleaseNotes.md +17 -0
  30. package/docs/ResourceCompleteness.html +2 -2
  31. package/docs/ResourceDNTTerms.html +10 -10
  32. package/docs/ResourceEdgeWhitespace.html +2 -2
  33. package/docs/ResourceICUPluralTranslation.html +2 -2
  34. package/docs/ResourceICUPlurals.html +2 -2
  35. package/docs/ResourceMatcher.html +2 -2
  36. package/docs/ResourceNoTranslation.html +2 -2
  37. package/docs/ResourceQuoteStyle.html +342 -6
  38. package/docs/ResourceRule.html +2 -2
  39. package/docs/ResourceSourceChecker.html +2 -2
  40. package/docs/ResourceSourceICUPluralCategories.html +2 -2
  41. package/docs/ResourceSourceICUPluralParams.html +2 -2
  42. package/docs/ResourceSourceICUPluralSyntax.html +2 -2
  43. package/docs/ResourceSourceICUUnexplainedParams.html +2 -2
  44. package/docs/ResourceStateChecker.html +2 -2
  45. package/docs/ResourceTargetChecker.html +2 -2
  46. package/docs/ResourceUniqueKeys.html +4 -4
  47. package/docs/ResultComparator.js.html +2 -2
  48. package/docs/RuleManager.html +2 -2
  49. package/docs/RuleManager.js.html +4 -4
  50. package/docs/RuleSet.html +142 -5
  51. package/docs/RuleSet.js.html +13 -2
  52. package/docs/SourceRegexpChecker.html +2 -2
  53. package/docs/StringFixCommand_StringFixCommand.html +2 -2
  54. package/docs/StringParser.html +4 -4
  55. package/docs/XliffParser.html +79 -5
  56. package/docs/config_Configuration.js.html +21 -3
  57. package/docs/config_ConfigurationProvider.js.html +21 -3
  58. package/docs/config_default.js.html +21 -3
  59. package/docs/formatters_AnsiConsoleFormatter.js.html +4 -4
  60. package/docs/formatters_ConfigBasedFormatter.js.html +4 -4
  61. package/docs/global.html +1090 -143
  62. package/docs/ilibLint.md +0 -0
  63. package/docs/index.html +2 -2
  64. package/docs/plugins_BuiltinPlugin.js.html +5 -5
  65. package/docs/plugins_LineParser.js.html +10 -10
  66. package/docs/plugins_XliffParser.js.html +18 -17
  67. package/docs/plugins_string_StringFix.js.html +4 -4
  68. package/docs/plugins_string_StringFixCommand.js.html +2 -2
  69. package/docs/plugins_string_StringFixer.js.html +4 -4
  70. package/docs/plugins_string_StringParser.js.html +8 -9
  71. package/docs/resource-xml.md +58 -0
  72. package/docs/rules_DeclarativeResourceRule.js.html +2 -2
  73. package/docs/rules_LineRegexpChecker.js.html +5 -5
  74. package/docs/rules_ResourceCompleteness.js.html +4 -4
  75. package/docs/rules_ResourceDNTTerms.js.html +4 -5
  76. package/docs/rules_ResourceEdgeWhitespace.js.html +4 -4
  77. package/docs/rules_ResourceICUPluralTranslation.js.html +4 -4
  78. package/docs/rules_ResourceICUPlurals.js.html +3 -3
  79. package/docs/rules_ResourceMatcher.js.html +3 -3
  80. package/docs/rules_ResourceNoTranslation.js.html +4 -4
  81. package/docs/rules_ResourceQuoteStyle.js.html +227 -122
  82. package/docs/rules_ResourceRule.js.html +4 -4
  83. package/docs/rules_ResourceSourceChecker.js.html +4 -4
  84. package/docs/rules_ResourceSourceICUPluralCategories.js.html +4 -4
  85. package/docs/rules_ResourceSourceICUPluralParams.js.html +4 -4
  86. package/docs/rules_ResourceSourceICUPluralSyntax.js.html +4 -4
  87. package/docs/rules_ResourceSourceICUUnexplainedParams.js.html +4 -4
  88. package/docs/rules_ResourceStateChecker.js.html +4 -4
  89. package/docs/rules_ResourceTargetChecker.js.html +4 -4
  90. package/docs/rules_ResourceUniqueKeys.js.html +4 -5
  91. package/docs/rules_SourceRegexpChecker.js.html +5 -5
  92. package/docs/rules_utils.js.html +2 -2
  93. package/package.json +13 -12
  94. package/src/LintableFile.js +7 -1
  95. package/src/formatters/AnsiConsoleFormatter.js +2 -1
  96. package/src/plugins/BuiltinPlugin.js +4 -1
  97. package/src/rules/ResourceXML.js +244 -0
@@ -0,0 +1,330 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+
5
+ <meta charset="utf-8">
6
+ <title>LintableFile.js - Documentation</title>
7
+
8
+
9
+ <script src="scripts/prettify/prettify.js"></script>
10
+ <script src="scripts/prettify/lang-css.js"></script>
11
+ <!--[if lt IE 9]>
12
+ <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
13
+ <![endif]-->
14
+ <link type="text/css" rel="stylesheet" href="styles/prettify.css">
15
+ <link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
16
+ <script src="scripts/nav.js" defer></script>
17
+
18
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
19
+ </head>
20
+ <body>
21
+
22
+ <input type="checkbox" id="nav-trigger" class="nav-trigger" />
23
+ <label for="nav-trigger" class="navicon-button x">
24
+ <div class="navicon"></div>
25
+ </label>
26
+
27
+ <label for="nav-trigger" class="overlay"></label>
28
+
29
+ <nav >
30
+
31
+
32
+ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="AnsiConsoleFormatter.html">AnsiConsoleFormatter</a><ul class='methods'><li data-type='method'><a href="AnsiConsoleFormatter.html#format">format</a></li></ul></li><li><a href="BuiltinPlugin.html">BuiltinPlugin</a><ul class='methods'><li data-type='method'><a href="BuiltinPlugin.html#getFormatters">getFormatters</a></li><li data-type='method'><a href="BuiltinPlugin.html#getParsers">getParsers</a></li><li data-type='method'><a href="BuiltinPlugin.html#getRuleSets">getRuleSets</a></li><li data-type='method'><a href="BuiltinPlugin.html#getRules">getRules</a></li></ul></li><li><a href="ConfigBasedFormatter.html">ConfigBasedFormatter</a><ul class='methods'><li data-type='method'><a href="ConfigBasedFormatter.html#format">format</a></li></ul></li><li><a href="DeclarativeResourceRule.html">DeclarativeResourceRule</a><ul class='methods'><li data-type='method'><a href="DeclarativeResourceRule.html#checkString">checkString</a></li><li data-type='method'><a href="DeclarativeResourceRule.html#matchString">matchString</a></li></ul></li><li><a href="DirItem.html">DirItem</a><ul class='methods'><li data-type='method'><a href="DirItem.html#findIssues">findIssues</a></li><li data-type='method'><a href="DirItem.html#getFilePath">getFilePath</a></li><li data-type='method'><a href="DirItem.html#parse">parse</a></li></ul></li><li><a href="FileConfigurationProvider.html">FileConfigurationProvider</a><ul class='methods'><li data-type='method'><a href="FileConfigurationProvider.html#loadJsConfiguration">loadJsConfiguration</a></li><li data-type='method'><a href="FileConfigurationProvider.html#loadJsonConfiguration">loadJsonConfiguration</a></li></ul></li><li><a href="FileType.html">FileType</a><ul class='methods'><li data-type='method'><a href="FileType.html#getParserClasses">getParserClasses</a></li><li data-type='method'><a href="FileType.html#getRuleSetNames">getRuleSetNames</a></li><li data-type='method'><a href="FileType.html#getRules">getRules</a></li></ul></li><li><a href="FixerManager.html">FixerManager</a><ul class='methods'><li data-type='method'><a href="FixerManager.html#add">add</a></li><li data-type='method'><a href="FixerManager.html#get">get</a></li><li data-type='method'><a href="FixerManager.html#size">size</a></li></ul></li><li><a href="FolderConfigurationProvider.html">FolderConfigurationProvider</a><ul class='methods'><li data-type='method'><a href="FolderConfigurationProvider.html#hasConfigurationFile">hasConfigurationFile</a></li></ul></li><li><a href="FormatterManager.html">FormatterManager</a><ul class='methods'><li data-type='method'><a href="FormatterManager.html#add">add</a></li><li data-type='method'><a href="FormatterManager.html#get">get</a></li><li data-type='method'><a href="FormatterManager.html#getDescriptions">getDescriptions</a></li><li data-type='method'><a href="FormatterManager.html#size">size</a></li></ul></li><li><a href="LineParser.html">LineParser</a><ul class='methods'><li data-type='method'><a href="LineParser.html#parse">parse</a></li></ul></li><li><a href="LineRegexpChecker.html">LineRegexpChecker</a><ul class='methods'><li data-type='method'><a href="LineRegexpChecker.html#match">match</a></li></ul></li><li><a href="LintableFile.html">LintableFile</a><ul class='methods'><li data-type='method'><a href="LintableFile.html#findIssues">findIssues</a></li><li data-type='method'><a href="LintableFile.html#getIRs">getIRs</a></li><li data-type='method'><a href="LintableFile.html#getLocaleFromPath">getLocaleFromPath</a></li><li data-type='method'><a href="LintableFile.html#getStats">getStats</a></li><li data-type='method'><a href="LintableFile.html#parse">parse</a></li></ul></li><li><a href="ParserManager.html">ParserManager</a><ul class='methods'><li data-type='method'><a href="ParserManager.html#add">add</a></li><li data-type='method'><a href="ParserManager.html#get">get</a></li><li data-type='method'><a href="ParserManager.html#getByName">getByName</a></li><li data-type='method'><a href="ParserManager.html#getDescriptions">getDescriptions</a></li></ul></li><li><a href="PluginManager.html">PluginManager</a><ul class='methods'><li data-type='method'><a href="PluginManager.html#add">add</a></li><li data-type='method'><a href="PluginManager.html#getFixerManager">getFixerManager</a></li><li data-type='method'><a href="PluginManager.html#getFormatterManager">getFormatterManager</a></li><li data-type='method'><a href="PluginManager.html#getParserManager">getParserManager</a></li><li data-type='method'><a href="PluginManager.html#getRuleManager">getRuleManager</a></li><li data-type='method'><a href="PluginManager.html#getRuleSet">getRuleSet</a></li><li data-type='method'><a href="PluginManager.html#load">load</a></li></ul></li><li><a href="Project.html">Project</a><ul class='methods'><li data-type='method'><a href="Project.html#add">add</a></li><li data-type='method'><a href="Project.html#findIssues">findIssues</a></li><li data-type='method'><a href="Project.html#get">get</a></li><li data-type='method'><a href="Project.html#getExcludes">getExcludes</a></li><li data-type='method'><a href="Project.html#getFileType">getFileType</a></li><li data-type='method'><a href="Project.html#getFileTypeForPath">getFileTypeForPath</a></li><li data-type='method'><a href="Project.html#getFixerManager">getFixerManager</a></li><li data-type='method'><a href="Project.html#getIncludes">getIncludes</a></li><li data-type='method'><a href="Project.html#getLocales">getLocales</a></li><li data-type='method'><a href="Project.html#getName">getName</a></li><li data-type='method'><a href="Project.html#getOptions">getOptions</a></li><li data-type='method'><a href="Project.html#getParserManager">getParserManager</a></li><li data-type='method'><a href="Project.html#getPluginManager">getPluginManager</a></li><li data-type='method'><a href="Project.html#getRoot">getRoot</a></li><li data-type='method'><a href="Project.html#getRuleManager">getRuleManager</a></li><li data-type='method'><a href="Project.html#getScore">getScore</a></li><li data-type='method'><a href="Project.html#getSourceLocale">getSourceLocale</a></li><li data-type='method'><a href="Project.html#init">init</a></li><li data-type='method'><a href="Project.html#run">run</a></li><li data-type='method'><a href="Project.html#scan">scan</a></li></ul></li><li><a href="ResourceCompleteness.html">ResourceCompleteness</a><ul class='methods'><li data-type='method'><a href="ResourceCompleteness.html#matchString">matchString</a></li></ul></li><li><a href="ResourceDNTTerms.html">ResourceDNTTerms</a><ul class='methods'><li data-type='method'><a href="ResourceDNTTerms.html#matchString">matchString</a></li><li data-type='method'><a href="ResourceDNTTerms.html#.parseTermsFromJsonFile">parseTermsFromJsonFile</a></li><li data-type='method'><a href="ResourceDNTTerms.html#.parseTermsFromTxtFile">parseTermsFromTxtFile</a></li></ul></li><li><a href="ResourceEdgeWhitespace.html">ResourceEdgeWhitespace</a><ul class='methods'><li data-type='method'><a href="ResourceEdgeWhitespace.html#matchString">matchString</a></li></ul></li><li><a href="ResourceICUPluralTranslation.html">ResourceICUPluralTranslation</a><ul class='methods'><li data-type='method'><a href="ResourceICUPluralTranslation.html#matchString">matchString</a></li></ul></li><li><a href="ResourceICUPlurals.html">ResourceICUPlurals</a></li><li><a href="ResourceMatcher.html">ResourceMatcher</a><ul class='methods'><li data-type='method'><a href="ResourceMatcher.html#checkString">checkString</a></li></ul></li><li><a href="ResourceNoTranslation.html">ResourceNoTranslation</a><ul class='methods'><li data-type='method'><a href="ResourceNoTranslation.html#matchString">matchString</a></li></ul></li><li><a href="ResourceQuoteStyle.html">ResourceQuoteStyle</a><ul class='methods'><li data-type='method'><a href="ResourceQuoteStyle.html#matchString">matchString</a></li></ul></li><li><a href="ResourceRule.html">ResourceRule</a><ul class='methods'><li data-type='method'><a href="ResourceRule.html#getRuleType">getRuleType</a></li><li data-type='method'><a href="ResourceRule.html#match">match</a></li><li data-type='method'><a href="ResourceRule.html#matchString">matchString</a></li></ul></li><li><a href="ResourceSourceChecker.html">ResourceSourceChecker</a><ul class='methods'><li data-type='method'><a href="ResourceSourceChecker.html#checkString">checkString</a></li></ul></li><li><a href="ResourceSourceICUPluralCategories.html">ResourceSourceICUPluralCategories</a><ul class='methods'><li data-type='method'><a href="ResourceSourceICUPluralCategories.html#matchString">matchString</a></li></ul></li><li><a href="ResourceSourceICUPluralParams.html">ResourceSourceICUPluralParams</a><ul class='methods'><li data-type='method'><a href="ResourceSourceICUPluralParams.html#matchString">matchString</a></li></ul></li><li><a href="ResourceSourceICUPluralSyntax.html">ResourceSourceICUPluralSyntax</a><ul class='methods'><li data-type='method'><a href="ResourceSourceICUPluralSyntax.html#matchString">matchString</a></li></ul></li><li><a href="ResourceSourceICUUnexplainedParams.html">ResourceSourceICUUnexplainedParams</a><ul class='methods'><li data-type='method'><a href="ResourceSourceICUUnexplainedParams.html#matchString">matchString</a></li></ul></li><li><a href="ResourceStateChecker.html">ResourceStateChecker</a><ul class='methods'><li data-type='method'><a href="ResourceStateChecker.html#match">match</a></li></ul></li><li><a href="ResourceTargetChecker.html">ResourceTargetChecker</a><ul class='methods'><li data-type='method'><a href="ResourceTargetChecker.html#checkString">checkString</a></li></ul></li><li><a href="ResourceUniqueKeys.html">ResourceUniqueKeys</a><ul class='methods'><li data-type='method'><a href="ResourceUniqueKeys.html#match">match</a></li></ul></li><li><a href="RuleManager.html">RuleManager</a><ul class='methods'><li data-type='method'><a href="RuleManager.html#add">add</a></li><li data-type='method'><a href="RuleManager.html#addRuleSetDefinition">addRuleSetDefinition</a></li><li data-type='method'><a href="RuleManager.html#addRuleSetDefinitions">addRuleSetDefinitions</a></li><li data-type='method'><a href="RuleManager.html#get">get</a></li><li data-type='method'><a href="RuleManager.html#getDescriptions">getDescriptions</a></li><li data-type='method'><a href="RuleManager.html#getRuleSetDefinition">getRuleSetDefinition</a></li><li data-type='method'><a href="RuleManager.html#getRuleSetDefinitions">getRuleSetDefinitions</a></li><li data-type='method'><a href="RuleManager.html#getRules">getRules</a></li><li data-type='method'><a href="RuleManager.html#size">size</a></li><li data-type='method'><a href="RuleManager.html#sizeRuleSetDefinitions">sizeRuleSetDefinitions</a></li></ul></li><li><a href="RuleSet.html">RuleSet</a><ul class='methods'><li data-type='method'><a href="RuleSet.html#add">add</a></li><li data-type='method'><a href="RuleSet.html#addRule">addRule</a></li><li data-type='method'><a href="RuleSet.html#getRule">getRule</a></li><li data-type='method'><a href="RuleSet.html#getRules">getRules</a></li><li data-type='method'><a href="RuleSet.html#getSize">getSize</a></li><li data-type='method'><a href="RuleSet.html#removeRule">removeRule</a></li></ul></li><li><a href="SourceRegexpChecker.html">SourceRegexpChecker</a><ul class='methods'><li data-type='method'><a href="SourceRegexpChecker.html#match">match</a></li></ul></li><li><a href="StringFixCommand_StringFixCommand.html">StringFixCommand</a></li><li><a href="StringParser.html">StringParser</a><ul class='methods'><li data-type='method'><a href="StringParser.html#parse">parse</a></li><li data-type='method'><a href="StringParser.html#write">write</a></li></ul></li><li><a href="XliffParser.html">XliffParser</a><ul class='methods'><li data-type='method'><a href="XliffParser.html#parse">parse</a></li></ul></li></ul><h3>Interfaces</h3><ul><li><a href="ConfigurationProvider.html">ConfigurationProvider</a></li><li><a href="ConfigurationProvider_loadConfiguration.html">loadConfiguration</a></li><li><a href="FileConfigurationProvider_loadConfiguration.html">loadConfiguration</a></li><li><a href="FolderConfigurationProvider_loadConfiguration.html">loadConfiguration</a></li></ul><h3>Global</h3><ul><li><a href="global.html#DeclarativeRuleTypes">DeclarativeRuleTypes</a></li><li><a href="global.html#ResultComparator">ResultComparator</a></li><li><a href="global.html#concatIntlAstText">concatIntlAstText</a></li><li><a href="global.html#defaultConfiguration">defaultConfiguration</a></li><li><a href="global.html#severity">severity</a></li><li><a href="global.html#typeMap">typeMap</a></li></ul>
33
+
34
+ </nav>
35
+
36
+ <div id="main">
37
+
38
+ <h1 class="page-title">LintableFile.js</h1>
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+ <section>
47
+ <article>
48
+ <pre class="prettyprint source linenums"><code>/*
49
+ * LintableFile.js - Represent a lintable source file
50
+ *
51
+ * Copyright © 2022-2024 JEDLSoft
52
+ *
53
+ * Licensed under the Apache License, Version 2.0 (the "License");
54
+ * you may not use this file except in compliance with the License.
55
+ * You may obtain a copy of the License at
56
+ *
57
+ * http://www.apache.org/licenses/LICENSE-2.0
58
+ *
59
+ * Unless required by applicable law or agreed to in writing, software
60
+ * distributed under the License is distributed on an "AS IS" BASIS,
61
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
62
+ *
63
+ * See the License for the specific language governing permissions and
64
+ * limitations under the License.
65
+ */
66
+
67
+ import path from "node:path";
68
+ import log4js from "log4js";
69
+ import { getLocaleFromPath } from "ilib-tools-common";
70
+ import { Fix, IntermediateRepresentation, Parser, Result, SourceFile, FileStats } from "ilib-lint-common";
71
+ import DirItem from "./DirItem.js";
72
+ import Project from "./Project.js";
73
+ import FileType from "./FileType.js";
74
+
75
+ const logger = log4js.getLogger("ilib-lint.root.LintableFile");
76
+
77
+ /**
78
+ * @class Represent a source file
79
+ */
80
+ class LintableFile extends DirItem {
81
+ /**
82
+ * Construct a source file instance
83
+ * The options parameter can contain any of the following properties:
84
+ *
85
+ *
86
+ * @constructor
87
+ * @param {String} filePath path to the source file
88
+ * @param {Object} options options for constructing this source file
89
+ * @param {FileType} options.filetype file type of this source file
90
+ * @param {String} options.filePath path to the file
91
+ * @param {object} [options.settings] additional settings from the ilib-lint config that apply to this file
92
+ * @param {Project} project the project where this file is located
93
+ */
94
+ constructor(filePath, options, project) {
95
+ super(filePath, options, project);
96
+ if (!options || !filePath || !options.filetype) {
97
+ throw "Incorrect options given to LintableFile constructor";
98
+ }
99
+ this.sourceFile = new SourceFile(filePath, {
100
+ sourceLocale: options.locale,
101
+ getLogger: log4js.getLogger.bind(log4js),
102
+ type: options.filetype.getName()
103
+ });
104
+ this.filetype = options.filetype;
105
+
106
+ if (this.project.options.opt?.verbose) {
107
+ logger.level = "debug";
108
+ }
109
+ this.parsers = [];
110
+ let extension = path.extname(filePath);
111
+ if (extension) {
112
+ // remove the dot
113
+ extension = extension.substring(1);
114
+ this.parsers = this.filetype.getParserClasses(extension);
115
+ }
116
+ }
117
+
118
+ /**
119
+ * Return the locale gleaned from the file path using the template in
120
+ * the settings, or undefined if no locale could be found.
121
+ *
122
+ * @returns {String} the locale gleaned from the path, or the empty
123
+ * string if no locale could be found.
124
+ */
125
+ getLocaleFromPath() {
126
+ if (this.settings?.template) {
127
+ return getLocaleFromPath(this.settings.template, this.sourceFile.getPath());
128
+ }
129
+ return "";
130
+ }
131
+
132
+ /**
133
+ * Parse the current source file into a list of Intermediate Representaitons
134
+ * @returns {Array.&lt;IntermediateRepresentation>} the parsed representations
135
+ * of this file
136
+ */
137
+ parse() {
138
+ if (!this.filePath) return [];
139
+ const irs = this.parsers.flatMap(parser => {
140
+ try {
141
+ return parser.parse(this.sourceFile);
142
+ } catch (e) {
143
+ logger.trace(`Parser ${parser.getName()} could not parse file ${this.sourceFile.getPath()}`);
144
+ logger.trace(e);
145
+ }
146
+ });
147
+ if (!irs || irs.length === 0) {
148
+ throw new Error(`All available parsers failed to parse file ${file.sourceFile.getPath()}. Try configuring another parser or excluding this file from the lint project.`);
149
+ }
150
+ return irs;
151
+ }
152
+
153
+ /**
154
+ * Check the current file and return a list of issues found in this file.
155
+ * This method parses the source file and applies each rule in turn
156
+ * using the given locales. Optionally, it also applies the available auto-fixes
157
+ * and overwrites the underlying file depending if it's enabled in the project config options.
158
+ *
159
+ * @param {Array.&lt;string>} locales a set of locales to apply
160
+ * @returns {Array.&lt;Result>} a list of natch results
161
+ */
162
+ findIssues(locales) {
163
+ const detectedLocale = this.getLocaleFromPath();
164
+
165
+ if (detectedLocale &amp;&amp; !locales.includes(detectedLocale)) {
166
+ // not one of the locales we need to check
167
+ return [];
168
+ }
169
+
170
+ if (!this.filePath) return [];
171
+ /**
172
+ * @type {IntermediateRepresentation[]}
173
+ */
174
+ this.irs = [];
175
+
176
+ const results = this.parsers.flatMap((parser) => {
177
+ const /** @type {Result[]} */ fixedResults = [];
178
+ let /** @type {Result[]} */ currentParseResults = [];
179
+
180
+ try {
181
+ let didWrite = false;
182
+ let irs;
183
+
184
+ do {
185
+ irs = parser.parse(this.sourceFile);
186
+ // indicate that for current intermediate representations, parser did not write out modified representations yet
187
+ didWrite = false;
188
+ // clear the results of the current parse, because the file had been overwritten
189
+ // (so the results don't match the file anymore)
190
+ currentParseResults = [];
191
+
192
+ for (const ir of irs) {
193
+ // find the rules that are appropriate for this intermediate representation and then apply them
194
+ const rules = this.filetype.getRules().filter((rule) => rule.getRuleType() === ir.getType());
195
+
196
+ rules.forEach(ru => {
197
+ logger.debug('Checking rule : ' + ru.name);
198
+ });
199
+ logger.debug('');
200
+
201
+ // apply rules
202
+ const results = rules.flatMap(
203
+ (rule) =>
204
+ rule.match({
205
+ ir,
206
+ locale: detectedLocale || this.project.getSourceLocale(),
207
+ file: this.filePath,
208
+ }) ?? []
209
+ ).filter(result => result);
210
+ const fixable = results.filter((result) => result?.fix !== undefined);
211
+
212
+ let fixer;
213
+ if (
214
+ // ensure that autofixing is enabled
215
+ true === this.project.getConfig().autofix &amp;&amp;
216
+ // and that any fixable results were produced
217
+ fixable.length > 0 &amp;&amp;
218
+ // and that the current parser is able to write
219
+ parser.canWrite &amp;&amp;
220
+ // and that the fixer for this type of IR is avaliable
221
+ (fixer = this.project.getFixerManager().get(ir.getType()))
222
+ ) {
223
+ // attempt to apply fixes to the current IR
224
+ const fixes = /** @type {Fix[]} */ (fixable.map((result) => result.fix));
225
+ fixer.applyFixes(ir, fixes);
226
+
227
+ // check if anything had been applied
228
+ if (fixes.some((fix) => fix.applied)) {
229
+ // fixer should modify the provided IR
230
+ // so tell current parser to write out the modified representation
231
+ parser.write(ir);
232
+
233
+ // after writing out the fixed content, we want to reparse to see if any new issues appeared,
234
+ // while preserving the results that have been fixed so far;
235
+ // fixer should have set the `applied` flag of each applied Fix
236
+ // so accumulate the corresponding results
237
+ fixedResults.push(...results.filter((result) => result.fix?.applied));
238
+
239
+ // indicate that the content has been modified and the re-parsing should occur
240
+ didWrite = true;
241
+
242
+ // don't process subsequent representations after modifying the file
243
+ // because they don't match the new file
244
+ break;
245
+ }
246
+ }
247
+
248
+ // otherwise, just accumulate the results of the current parse for each IRs
249
+ currentParseResults.push(...results);
250
+ }
251
+
252
+ // if a write had occurred for a given parser, reparse
253
+ } while (didWrite);
254
+ this.irs = this.irs.concat(irs);
255
+ } catch (e) {
256
+ if (this.parsers.length === 1) {
257
+ // if this is the only parser for this file, throw an exception right away so the user
258
+ // can see what the specific parse error was from the parser
259
+ throw new Error(`Could not parse file ${this.sourceFile.getPath()}. Try configuring another parser or excluding this file from the lint project.`, {
260
+ cause: e
261
+ });
262
+ }
263
+ logger.trace(`Parser ${parser.getName()} could not parse file ${this.sourceFile.getPath()}`);
264
+ logger.trace(e);
265
+ }
266
+
267
+ // once all intermediate representations have been processed for the given parser
268
+ // without any writes, finally return all of the results accumulated during auto-fixing
269
+ // and the remaining ones that were produced
270
+ return [...fixedResults, ...currentParseResults];
271
+ });
272
+ if (this.irs.length === 0) {
273
+ throw new Error(`All available parsers failed to parse file ${this.sourceFile.getPath()}. Try configuring another parser or excluding this file from the lint project.`);
274
+ }
275
+
276
+ return results;
277
+ }
278
+
279
+ /**
280
+ * Get the intermediate representations of this file.
281
+ * @returns {Array.&lt;IntermediateRepresentation>} the intermediate representations
282
+ * of this file
283
+ */
284
+ getIRs() {
285
+ return this.irs;
286
+ }
287
+
288
+ /**
289
+ * Return the stats for the file after issues were found.
290
+ * @returns {FileStats} the stats for the current file
291
+ */
292
+ getStats() {
293
+ const fileStats = new FileStats();
294
+ if (this.irs) {
295
+ this.irs.forEach(ir => {
296
+ if (ir.stats) {
297
+ fileStats.addStats(ir.stats);
298
+ }
299
+ });
300
+ }
301
+ return fileStats;
302
+ }
303
+ }
304
+
305
+ export default LintableFile;
306
+ </code></pre>
307
+ </article>
308
+ </section>
309
+
310
+
311
+
312
+
313
+
314
+
315
+ </div>
316
+
317
+ <br class="clear">
318
+
319
+ <footer>
320
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.3</a> on Tue Jul 09 2024 11:26:16 GMT-0700 (Pacific Daylight Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
321
+ </footer>
322
+
323
+ <script>prettyPrint();</script>
324
+ <script src="scripts/polyfill.js"></script>
325
+ <script src="scripts/linenumber.js"></script>
326
+
327
+
328
+
329
+ </body>
330
+ </html>