@mocoto/mahoraga 0.14.1 → 0.14.3

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 (306) hide show
  1. package/README.md +0 -34
  2. package/dist/analysts/architects/analyst-structure.js +20 -20
  3. package/dist/analysts/architects/archetypes-custom.js +16 -19
  4. package/dist/analysts/architects/detector-archetypes.js +43 -36
  5. package/dist/analysts/architects/orchestrator-archetypes.js +3 -3
  6. package/dist/analysts/architects/signals-project-advanced.js +26 -28
  7. package/dist/analysts/architects/signals-project.js +2 -2
  8. package/dist/analysts/architects/strategist-structure.js +47 -66
  9. package/dist/analysts/azure-pipelines/analysts/analyst-azure.js +41 -35
  10. package/dist/analysts/azure-pipelines/corrections/correction-azure.js +22 -19
  11. package/dist/analysts/azure-pipelines/detectors/detector-azure-performance.js +21 -18
  12. package/dist/analysts/azure-pipelines/detectors/detector-azure-security.js +25 -20
  13. package/dist/analysts/azure-pipelines/detectors/detector-azure-structure.js +39 -40
  14. package/dist/analysts/azure-pipelines/scorers/scorer-azure.js +10 -7
  15. package/dist/analysts/circleci/analysts/analyst-circleci.js +33 -27
  16. package/dist/analysts/circleci/corrections/correction-circleci.js +22 -20
  17. package/dist/analysts/circleci/detectors/detector-circleci-performance.js +23 -19
  18. package/dist/analysts/circleci/detectors/detector-circleci-security.js +78 -82
  19. package/dist/analysts/circleci/detectors/detector-circleci-structure.js +22 -22
  20. package/dist/analysts/converters/convert-registry.js +1 -1
  21. package/dist/analysts/converters/engines/converter-gha-to-gitlab.js +17 -15
  22. package/dist/analysts/converters/index.js +1 -1
  23. package/dist/analysts/corrections/analyst-quick-fixes.js +25 -28
  24. package/dist/analysts/corrections/analyst-scoring.js +24 -21
  25. package/dist/analysts/corrections/auto-fix-engine.js +1 -1
  26. package/dist/analysts/corrections/corrector-structure.js +43 -42
  27. package/dist/analysts/corrections/fix-alias-imports.js +10 -6
  28. package/dist/analysts/corrections/fix-md-fences.js +23 -23
  29. package/dist/analysts/corrections/map-reversion.js +56 -53
  30. package/dist/analysts/corrections/pruning.js +19 -16
  31. package/dist/analysts/corrections/quick-fixes/fix-any-to-proper-type.js +57 -61
  32. package/dist/analysts/corrections/quick-fixes/fix-unknown-to-specific-type.js +30 -30
  33. package/dist/analysts/corrections/reorganize-barrels.js +13 -13
  34. package/dist/analysts/corrections/rewrite-testes-aliases.js +23 -22
  35. package/dist/analysts/corrections/scoring-shared.js +19 -18
  36. package/dist/analysts/corrections/type-safety/context-analyzer.js +15 -10
  37. package/dist/analysts/corrections/type-safety/type-analyzer.js +3 -3
  38. package/dist/analysts/corrections/type-safety/type-validator.js +4 -3
  39. package/dist/analysts/corrections/type-safety/usage-analyzer.js +39 -42
  40. package/dist/analysts/css/analysts/analyst-css.js +42 -42
  41. package/dist/analysts/css/corrections/correction-css.js +19 -11
  42. package/dist/analysts/css/detectors/detector-css-best-practices.js +129 -118
  43. package/dist/analysts/css/scorers/scorer-css.js +23 -18
  44. package/dist/analysts/css-in-js/analysts/analyst-css-in-js.js +24 -17
  45. package/dist/analysts/css-in-js/corrections/correction-css-in-js.js +31 -16
  46. package/dist/analysts/css-in-js/detectors/detector-css-in-js-best-practices.js +28 -30
  47. package/dist/analysts/css-in-js/scorers/scorer-css-in-js.js +79 -54
  48. package/dist/analysts/css-in-js/shared.js +7 -0
  49. package/dist/analysts/detectors/detector-architecture.js +91 -85
  50. package/dist/analysts/detectors/detector-bugs-ml.js +29 -27
  51. package/dist/analysts/detectors/detector-code-fragile.js +41 -36
  52. package/dist/analysts/detectors/detector-dependencies.js +5 -5
  53. package/dist/analysts/detectors/detector-duplications.js +26 -26
  54. package/dist/analysts/detectors/detector-monorepo.js +51 -45
  55. package/dist/analysts/detectors/detector-performance.js +24 -17
  56. package/dist/analysts/detectors/detector-recommendation-architecture.js +40 -36
  57. package/dist/analysts/detectors/detector-security.js +43 -42
  58. package/dist/analysts/detectors/detector-structure.js +31 -28
  59. package/dist/analysts/github-actions/analysts/analyst-github-actions.js +5 -8
  60. package/dist/analysts/github-actions/detectors/detector-workflow-accessibility.js +1 -9
  61. package/dist/analysts/github-actions/detectors/detector-workflow-structure.js +1 -4
  62. package/dist/analysts/github-actions/detectors/detector-workflow-trigger-unsafe.js +6 -5
  63. package/dist/analysts/gitlab-ci/analysts/analyst-gitlab-ci.js +2 -2
  64. package/dist/analysts/gitlab-ci/detectors/detector-gitlab-ci-structure.js +0 -3
  65. package/dist/analysts/go/analysts/analyst-best-practices.js +2 -2
  66. package/dist/analysts/go/analysts/analyst-concurrency.js +1 -1
  67. package/dist/analysts/go/analysts/analyst-security.js +1 -1
  68. package/dist/analysts/go/detectors/detector-conventions.js +1 -1
  69. package/dist/analysts/html/analysts/analyst-html.js +10 -12
  70. package/dist/analysts/html/detectors/detector-html.js +3 -3
  71. package/dist/analysts/js-ts/analysts/analyst-commands-cli.js +22 -22
  72. package/dist/analysts/js-ts/analysts/analyst-functions-long.js +5 -5
  73. package/dist/analysts/js-ts/analysts/analyst-patterns-usage.js +6 -2
  74. package/dist/analysts/js-ts/detectors/detector-anti-patterns-async.js +84 -9
  75. package/dist/analysts/js-ts/detectors/detector-constructions-syntactic.js +33 -10
  76. package/dist/analysts/js-ts/detectors/detector-context-smart.js +6 -6
  77. package/dist/analysts/js-ts/detectors/detector-leaks-memory.js +1 -1
  78. package/dist/analysts/js-ts/detectors/detector-types-unsafe.js +33 -2
  79. package/dist/analysts/php/analysts/analyst-php.js +3 -3
  80. package/dist/analysts/php/detectors/detector-php-best-practices.js +5 -5
  81. package/dist/analysts/php/detectors/detector-php-security.js +5 -5
  82. package/dist/analysts/php/scorers/scorer-php.js +2 -2
  83. package/dist/analysts/plugins/detector-documentation.js +6 -6
  84. package/dist/analysts/plugins/detector-markdown.js +7 -7
  85. package/dist/analysts/python/analysts/analyst-python.js +2 -5
  86. package/dist/analysts/react/analysts/analyst-react-hooks.js +66 -9
  87. package/dist/analysts/react/analysts/analyst-react.js +46 -2
  88. package/dist/analysts/react/corrections/correction-react.js +41 -1
  89. package/dist/analysts/react/detectors/detector-react-best-practices.js +5 -5
  90. package/dist/analysts/react/scorers/scorer-react.js +36 -1
  91. package/dist/analysts/registry/autodiscovery.js +2 -2
  92. package/dist/analysts/rust/analysts/analyst-best-practices.js +42 -3
  93. package/dist/analysts/rust/analysts/analyst-memory.js +2 -2
  94. package/dist/analysts/rust/analysts/analyst-rust.js +52 -5
  95. package/dist/analysts/rust/analysts/analyst-security.js +29 -1
  96. package/dist/analysts/scorers/scorer.js +5 -5
  97. package/dist/analysts/shell/analysts/analyst-shell.js +81 -5
  98. package/dist/analysts/shell/corrections/correction-shell.js +34 -1
  99. package/dist/analysts/shell/detectors/detector-shell-security.js +88 -0
  100. package/dist/analysts/shell/scorers/scorer-shell.js +58 -1
  101. package/dist/analysts/strategists/operator-structure.js +5 -7
  102. package/dist/analysts/strategists/suggestions-contextuais.js +5 -2
  103. package/dist/analysts/svg/analysts/analyst-svg.js +1 -0
  104. package/dist/analysts/tailwind/analysts/analyst-tailwind.js +79 -55
  105. package/dist/analysts/tailwind/corrections/correction-tailwind.js +108 -9
  106. package/dist/analysts/tailwind/detectors/detector-tailwind-best-practices.js +122 -7
  107. package/dist/analysts/tailwind/scorers/scorer-tailwind.js +62 -11
  108. package/dist/analysts/xml/analysts/analyst-xml.js +2 -2
  109. package/dist/app/index.js +1 -0
  110. package/dist/bin/cli-bootstrap.js +6 -4
  111. package/dist/bin/index.js +6 -4
  112. package/dist/caretakers/scoring.js +1 -0
  113. package/dist/cli/commands/command-analysts.js +4 -3
  114. package/dist/cli/commands/command-azure.js +1 -1
  115. package/dist/cli/commands/command-circleci.js +1 -1
  116. package/dist/cli/commands/command-compliance.js +1 -1
  117. package/dist/cli/commands/command-diagnose.js +10 -13
  118. package/dist/cli/commands/command-fix-types.js +9 -32
  119. package/dist/cli/commands/command-formatters.js +2 -2
  120. package/dist/cli/commands/command-github-actions.js +1 -1
  121. package/dist/cli/commands/command-gitlab-ci.js +1 -1
  122. package/dist/cli/commands/command-guardian.js +1 -1
  123. package/dist/cli/commands/command-imports.js +6 -6
  124. package/dist/cli/commands/command-jenkins.js +1 -1
  125. package/dist/cli/commands/command-licenses.js +1 -1
  126. package/dist/cli/commands/command-marketplace.js +7 -7
  127. package/dist/cli/commands/command-names.js +3 -8
  128. package/dist/cli/commands/command-perf.js +7 -9
  129. package/dist/cli/commands/command-plugins.js +4 -4
  130. package/dist/cli/diagnostic/auto-fix.js +2 -2
  131. package/dist/cli/diagnostic/exporters/json-exporter.js +1 -1
  132. package/dist/cli/diagnostic/exporters/sharded-exporter.js +0 -3
  133. package/dist/cli/diagnostic/exporters/svg-optimization-exporter.js +1 -1
  134. package/dist/cli/diagnostic/filters.js +9 -9
  135. package/dist/cli/diagnostic/handlers/archetype-handler.js +3 -6
  136. package/dist/cli/diagnostic/handlers/auto-fix-handler.js +4 -4
  137. package/dist/cli/diagnostic/handlers/guardian-handler.js +1 -1
  138. package/dist/cli/diagnostic/processing-diagnostic.js +31 -35
  139. package/dist/cli/diagnostic/processing-helpers.js +2 -2
  140. package/dist/cli/handlers/fix-types-exporter.js +1 -4
  141. package/dist/cli/helpers/display-frame.js +5 -5
  142. package/dist/core/config/auto/auto-fix-config.js +0 -6
  143. package/dist/core/config/chalk-safe.js +6 -6
  144. package/dist/core/config/config.js +11 -13
  145. package/dist/core/config/conventions.js +1 -1
  146. package/dist/core/config/security.js +2 -2
  147. package/dist/core/execution/analysis-cache.js +5 -8
  148. package/dist/core/execution/ast-cache.js +1 -3
  149. package/dist/core/execution/executor.js +8 -21
  150. package/dist/core/execution/inquisitor.js +24 -21
  151. package/dist/core/execution/results.js +1 -0
  152. package/dist/core/execution/scanner.js +4 -4
  153. package/dist/core/messages/en/analysts/analyst-github-actions-messages.js +1 -1
  154. package/dist/core/messages/en/analysts/analyst-patterns-usage-messages.js +1 -0
  155. package/dist/core/messages/en/analysts/analyst-shell-messages.js +15 -0
  156. package/dist/core/messages/en/analysts/detector-constructions-syntactic-messages.js +6 -0
  157. package/dist/core/messages/en/analysts/detector-js-ts-messages.js +27 -0
  158. package/dist/core/messages/en/analysts/detector-react-messages.js +8 -0
  159. package/dist/core/messages/en/analysts/detector-shell-messages.js +17 -0
  160. package/dist/core/messages/en/analysts/detector-tailwind-messages.js +3 -3
  161. package/dist/core/messages/en/analysts/report-circleci-messages.js +7 -7
  162. package/dist/core/messages/en/caretakers/caretaker-messages.js +1 -7
  163. package/dist/core/messages/en/core/plugin-messages.js +31 -3
  164. package/dist/core/messages/en/log/log.js +4 -4
  165. package/dist/core/messages/en/ui/filter-config.js +1 -5
  166. package/dist/core/messages/i18n-system.js +3 -3
  167. package/dist/core/messages/index.js +3 -3
  168. package/dist/core/messages/ja/analysts/analyst-github-actions-messages.js +1 -1
  169. package/dist/core/messages/ja/analysts/analyst-patterns-usage-messages.js +1 -0
  170. package/dist/core/messages/ja/analysts/analyst-shell-messages.js +15 -0
  171. package/dist/core/messages/ja/analysts/detector-constructions-syntactic-messages.js +6 -0
  172. package/dist/core/messages/ja/analysts/detector-js-ts-messages.js +27 -0
  173. package/dist/core/messages/ja/analysts/detector-react-messages.js +8 -0
  174. package/dist/core/messages/ja/analysts/detector-shell-messages.js +17 -0
  175. package/dist/core/messages/ja/analysts/detector-tailwind-messages.js +3 -3
  176. package/dist/core/messages/ja/analysts/report-circleci-messages.js +7 -7
  177. package/dist/core/messages/ja/caretakers/caretaker-messages.js +1 -7
  178. package/dist/core/messages/ja/core/plugin-messages.js +31 -3
  179. package/dist/core/messages/ja/log/log.js +4 -4
  180. package/dist/core/messages/ja/ui/filter-config.js +1 -1
  181. package/dist/core/messages/pt/analysts/analyst-github-actions-messages.js +1 -1
  182. package/dist/core/messages/pt/analysts/analyst-patterns-usage-messages.js +1 -0
  183. package/dist/core/messages/pt/analysts/analyst-shell-messages.js +15 -0
  184. package/dist/core/messages/pt/analysts/detector-constructions-syntactic-messages.js +6 -0
  185. package/dist/core/messages/pt/analysts/detector-js-ts-messages.js +27 -0
  186. package/dist/core/messages/pt/analysts/detector-react-messages.js +8 -0
  187. package/dist/core/messages/pt/analysts/detector-shell-messages.js +17 -0
  188. package/dist/core/messages/pt/analysts/detector-tailwind-messages.js +3 -3
  189. package/dist/core/messages/pt/analysts/report-circleci-messages.js +7 -7
  190. package/dist/core/messages/pt/caretakers/caretaker-messages.js +1 -7
  191. package/dist/core/messages/pt/core/plugin-messages.js +31 -3
  192. package/dist/core/messages/pt/log/log-engine.js +6 -6
  193. package/dist/core/messages/pt/log/log.js +3 -3
  194. package/dist/core/messages/pt/ui/filter-config.js +1 -1
  195. package/dist/core/messages/shared/icons.js +3 -3
  196. package/dist/core/messages/zh/analysts/analyst-github-actions-messages.js +1 -1
  197. package/dist/core/messages/zh/analysts/analyst-patterns-usage-messages.js +1 -0
  198. package/dist/core/messages/zh/analysts/analyst-shell-messages.js +15 -0
  199. package/dist/core/messages/zh/analysts/detector-constructions-syntactic-messages.js +6 -0
  200. package/dist/core/messages/zh/analysts/detector-js-ts-messages.js +27 -0
  201. package/dist/core/messages/zh/analysts/detector-react-messages.js +8 -0
  202. package/dist/core/messages/zh/analysts/detector-shell-messages.js +17 -0
  203. package/dist/core/messages/zh/analysts/detector-tailwind-messages.js +3 -3
  204. package/dist/core/messages/zh/analysts/report-circleci-messages.js +7 -7
  205. package/dist/core/messages/zh/caretakers/caretaker-messages.js +1 -7
  206. package/dist/core/messages/zh/core/plugin-messages.js +31 -3
  207. package/dist/core/messages/zh/log/log.js +3 -3
  208. package/dist/core/messages/zh/ui/filter-config.js +1 -5
  209. package/dist/core/parsing/filters.js +3 -3
  210. package/dist/core/parsing/langs/json.js +1 -1
  211. package/dist/core/parsing/langs/python.js +1 -1
  212. package/dist/core/parsing/langs/typescript.js +1 -1
  213. package/dist/core/parsing/parser.js +3 -4
  214. package/dist/core/parsing/utils.js +1 -0
  215. package/dist/core/registry/file-registry.js +3 -2
  216. package/dist/core/registry/paths.js +3 -3
  217. package/dist/core/reporting/default-reporter.js +2 -2
  218. package/dist/core/schema/version.js +6 -6
  219. package/dist/core/workers/worker-executor.js +3 -3
  220. package/dist/core/workers/worker-pool.js +0 -0
  221. package/dist/guardian/baseline.js +1 -1
  222. package/dist/guardian/gpg.js +3 -1
  223. package/dist/guardian/integrity.js +2 -7
  224. package/dist/guardian/records.js +7 -1
  225. package/dist/guardian/result.js +1 -1
  226. package/dist/guardian/sentinel.js +7 -1
  227. package/dist/guardian/watcher-hidden.js +6 -1
  228. package/dist/licenses/fs-utils.js +5 -1
  229. package/dist/licenses/generate-notices.js +1 -1
  230. package/dist/licenses/index.js +1 -0
  231. package/dist/licenses/normalizer.js +10 -9
  232. package/dist/node.loader.js +224 -4
  233. package/dist/reports/analise-async-patterns.js +1 -1
  234. package/dist/reports/filter-smart.js +2 -5
  235. package/dist/reports/generator-report.js +7 -7
  236. package/dist/reports/report-archetypes.js +10 -10
  237. package/dist/reports/report-caretaker-health.js +2 -1
  238. package/dist/reports/report-patterns-usage.js +1 -1
  239. package/dist/sdk/analyzer.js +1 -1
  240. package/dist/shared/data-processing/fragment-report.js +11 -11
  241. package/dist/shared/data-processing/json.js +1 -1
  242. package/dist/shared/data-processing/occurrences.js +3 -2
  243. package/dist/shared/formatters/code-min-formatter.js +1 -1
  244. package/dist/shared/formatters/engines/prettier.js +1 -1
  245. package/dist/shared/formatters/engines/stylelint.js +43 -40
  246. package/dist/shared/formatters/formatter.js +8 -8
  247. package/dist/shared/formatters/formatters/code.js +3 -3
  248. package/dist/shared/formatters/formatters/css.js +2 -10
  249. package/dist/shared/formatters/formatters/dotfiles.js +1 -1
  250. package/dist/shared/formatters/formatters/html.js +1 -5
  251. package/dist/shared/formatters/formatters/json.js +0 -3
  252. package/dist/shared/formatters/formatters/markdown.js +19 -24
  253. package/dist/shared/formatters/formatters/properties.js +2 -2
  254. package/dist/shared/formatters/formatters/shell.js +1 -4
  255. package/dist/shared/formatters/formatters/sql.js +0 -3
  256. package/dist/shared/formatters/formatters/xml.js +5 -7
  257. package/dist/shared/formatters/formatters/yaml.js +2 -7
  258. package/dist/shared/formatters/index.js +1 -1
  259. package/dist/shared/helpers/framework-detector.js +6 -2
  260. package/dist/shared/helpers/json.js +1 -1
  261. package/dist/shared/helpers/magic-constants-whitelist.js +1 -1
  262. package/dist/shared/helpers/masking.js +17 -17
  263. package/dist/shared/helpers/reader-report.js +0 -12
  264. package/dist/shared/helpers/structural-hash.js +3 -2
  265. package/dist/shared/helpers/structure.js +1 -1
  266. package/dist/shared/marketplace/registry.js +1 -1
  267. package/dist/shared/marketplace/remote.js +4 -4
  268. package/dist/shared/persistence/persistence.js +13 -6
  269. package/dist/shared/plugins/core-plugin.js +5 -1
  270. package/dist/shared/plugins/registry.js +3 -2
  271. package/dist/types/analysts/tailwind-correction.js +2 -0
  272. package/dist/types/caretakers/imports-barrel.js +1 -0
  273. package/dist/types/caretakers/index.js +4 -0
  274. package/dist/types/caretakers/map-reversion.js +1 -0
  275. package/dist/types/caretakers/pruning.js +1 -0
  276. package/dist/types/caretakers/scoring.js +1 -0
  277. package/dist/types/common/analysts.js +1 -1
  278. package/dist/types/core/config/filters.js +1 -0
  279. package/dist/types/core/config/index.js +2 -0
  280. package/dist/types/core/execution/ambiente.js +1 -0
  281. package/dist/types/core/execution/linguagens.js +1 -0
  282. package/dist/types/core/execution/parse-errors.js +1 -0
  283. package/dist/types/core/execution/results.js +1 -0
  284. package/dist/types/core/execution/structure-json.js +1 -0
  285. package/dist/types/core/index.js +1 -0
  286. package/dist/types/core/messages/index.js +1 -0
  287. package/dist/types/core/messages/log.js +1 -0
  288. package/dist/types/core/parsing/babel-narrow.js +1 -0
  289. package/dist/types/core/parsing/index.js +1 -0
  290. package/dist/types/core/runtime.js +1 -0
  291. package/dist/types/guardian/index.js +2 -0
  292. package/dist/types/guardian/integrity.js +7 -0
  293. package/dist/types/guardian/snapshot.js +1 -0
  294. package/dist/types/index.js +4 -4
  295. package/dist/types/licenses/index.js +2 -0
  296. package/dist/types/processing/display.js +16 -13
  297. package/dist/types/processing/filters.js +8 -11
  298. package/dist/types/reports/compliance.js +1 -0
  299. package/dist/types/reports/streaming.js +1 -0
  300. package/dist/types/scripts/index.js +1 -0
  301. package/dist/types/scripts/migrar-aliases.js +1 -0
  302. package/dist/types/sdk/index.js +1 -0
  303. package/dist/types/shared/index.js +2 -0
  304. package/dist/types/vulnerabilities/index.js +2 -0
  305. package/dist/vulnerabilities/scanner.js +3 -2
  306. package/package.json +14 -20
@@ -10,7 +10,7 @@
10
10
  */
11
11
  export function dedupeOcorrencias(arr) {
12
12
  const seen = new Map();
13
- for (const ocorrencia of arr || []) {
13
+ for (const ocorrencia of arr) {
14
14
  const key = `${ocorrencia.relPath ?? ''}|${String(ocorrencia.linha ?? '')}|${ocorrencia.tipo ?? ''}|${ocorrencia.mensagem ?? ''}`;
15
15
  if (!seen.has(key)) {
16
16
  seen.set(key, ocorrencia);
@@ -28,7 +28,8 @@ export function agruparAnalistas(analistas) {
28
28
  }
29
29
  const map = new Map();
30
30
  for (const arquivo of analistas) {
31
- const nome = String(arquivo['nome'] ?? 'desconhecido');
31
+ const rawNome = arquivo['nome'];
32
+ const nome = typeof rawNome === 'string' ? rawNome : 'desconhecido';
32
33
  const dur = Number(arquivo['duracaoMs'] ?? 0);
33
34
  const occ = Number(arquivo['ocorrencias'] ?? 0);
34
35
  const globalFlag = Boolean(arquivo['global'] ?? false);
@@ -10,7 +10,7 @@ export function formatarCodeMinimo(code, opts) {
10
10
  const formatted = normalizarNewlinesFinais(removerEspacosFinaisPorLinha(normalized));
11
11
  return {
12
12
  ok: true,
13
- parser: opts?.parser ?? 'code',
13
+ parser: opts?.parser,
14
14
  formatted,
15
15
  changed: formatted !== normalizarNewlinesFinais(normalized),
16
16
  };
@@ -18,7 +18,7 @@ async function carregarPrettierDoProjeto(baseDir) {
18
18
  const tryImportPrettier = async (resolved) => {
19
19
  try {
20
20
  const mod = await import(resolved);
21
- const candidate = mod && typeof mod === 'object' && 'default' in mod ? mod.default : mod;
21
+ const candidate = typeof mod === 'object' && 'default' in mod ? mod.default : mod;
22
22
  if (!candidate || !isPrettierApi(candidate)) {
23
23
  return null;
24
24
  }
@@ -5,7 +5,7 @@
5
5
  * Importante: este arquivo NÃO usa nem depende dos artefatos em /implis.
6
6
  * A pasta implis serve apenas como referência/"inspiração" de regras.
7
7
  */
8
- import * as csstree from 'css-tree';
8
+ import postcss, {} from 'postcss';
9
9
  function normalizeWhitespace(input) {
10
10
  return input.replace(/\s+/g, ' ').trim();
11
11
  }
@@ -104,11 +104,7 @@ export function lintCssLikeStylelint(opts) {
104
104
  warnings.push(...checkNoInvalidDoubleSlashComments(code));
105
105
  let ast;
106
106
  try {
107
- ast = csstree.parse(code, {
108
- filename: opts.relPath,
109
- positions: true,
110
- parseCustomProperty: true
111
- });
107
+ ast = postcss.parse(code, { from: opts.relPath });
112
108
  }
113
109
  catch (erro) {
114
110
  warnings.push({
@@ -132,10 +128,13 @@ export function lintCssLikeStylelint(opts) {
132
128
  }).join(' | ');
133
129
  }
134
130
  function generateNodeText(node) {
135
- return node.prelude ? normalizeWhitespace(csstree.generate(node.prelude)) : '';
131
+ if (node.type === 'atrule' && typeof node.params === 'string') {
132
+ return normalizeWhitespace(node.params);
133
+ }
134
+ return '';
136
135
  }
137
136
  function checkAtImport(node) {
138
- if (node.type !== 'Atrule' || String(node.name ?? '').toLowerCase() !== 'import') {
137
+ if (node.type !== 'atrule' || typeof node.name !== 'string' || node.name.toLowerCase() !== 'import') {
139
138
  return;
140
139
  }
141
140
  const prelude = generateNodeText(node);
@@ -165,10 +164,10 @@ export function lintCssLikeStylelint(opts) {
165
164
  }
166
165
  }
167
166
  function checkKeyframes(node) {
168
- if (node.type !== 'Atrule') {
167
+ if (node.type !== 'atrule') {
169
168
  return;
170
169
  }
171
- const name = String(node.name ?? '').toLowerCase();
170
+ const name = typeof node.name === 'string' ? node.name.toLowerCase() : '';
172
171
  const isKeyframes = name === 'keyframes' || name === '-webkit-keyframes' || name === '-moz-keyframes';
173
172
  if (!isKeyframes) {
174
173
  return;
@@ -189,18 +188,18 @@ export function lintCssLikeStylelint(opts) {
189
188
  }
190
189
  }
191
190
  function pushAtRuleScope(node) {
192
- if (node.type !== 'Atrule' || !node.block) {
191
+ if (node.type !== 'atrule' || !Array.isArray(node.nodes)) {
193
192
  return;
194
193
  }
195
- const name = String(node.name ?? '').toLowerCase();
194
+ const name = typeof node.name === 'string' ? node.name.toLowerCase() : '';
196
195
  const prelude = generateNodeText(node);
197
196
  atruleStack.push({ name, prelude });
198
197
  }
199
198
  function checkDuplicateSelector(node) {
200
- if (node.type !== 'Rule' || !node.prelude) {
199
+ if (node.type !== 'rule' || typeof node.selector !== 'string') {
201
200
  return;
202
201
  }
203
- const selector = normalizeWhitespace(csstree.generate(node.prelude));
202
+ const selector = normalizeWhitespace(node.selector);
204
203
  if (!selector) {
205
204
  return;
206
205
  }
@@ -219,15 +218,10 @@ export function lintCssLikeStylelint(opts) {
219
218
  }
220
219
  }
221
220
  function checkEmptyBlock(node) {
222
- if (node.type !== 'Rule' && node.type !== 'Atrule') {
223
- return;
224
- }
225
- if (!node.block?.children) {
221
+ if (node.type !== 'rule' && node.type !== 'atrule') {
226
222
  return;
227
223
  }
228
- const children = node.block.children;
229
- const isEmpty = typeof children.getSize === 'function' ? children.getSize() === 0 : false;
230
- if (!isEmpty) {
224
+ if (!Array.isArray(node.nodes) || node.nodes.length > 0) {
231
225
  return;
232
226
  }
233
227
  const loc = node.loc?.start;
@@ -253,7 +247,19 @@ export function lintCssLikeStylelint(opts) {
253
247
  column: loc.column
254
248
  });
255
249
  }
256
- csstree.walk(ast, {
250
+ function walk(node, visitor) {
251
+ if (typeof node !== 'object') {
252
+ return;
253
+ }
254
+ visitor.enter?.(node);
255
+ if (Array.isArray(node.nodes)) {
256
+ for (const child of node.nodes) {
257
+ walk(child, visitor);
258
+ }
259
+ }
260
+ visitor.leave?.(node);
261
+ }
262
+ walk(ast, {
257
263
  enter: (node) => {
258
264
  checkAtImport(node);
259
265
  checkKeyframes(node);
@@ -262,7 +268,7 @@ export function lintCssLikeStylelint(opts) {
262
268
  checkEmptyBlock(node);
263
269
  },
264
270
  leave: (node) => {
265
- if (node.type === 'Atrule' && node.block) {
271
+ if (node.type === 'atrule' && Array.isArray(node.nodes)) {
266
272
  atruleStack.pop();
267
273
  }
268
274
  }
@@ -272,25 +278,25 @@ export function lintCssLikeStylelint(opts) {
272
278
  const atruleStackForDecl = [];
273
279
  const declStack = [];
274
280
  function generateNodeTextSimple(prelude) {
275
- return prelude ? normalizeWhitespace(csstree.generate(prelude)) : '';
281
+ return prelude && typeof prelude !== 'object' ? normalizeWhitespace(prelude) : '';
276
282
  }
277
283
  function pushAtRuleDeclStack(node) {
278
- if (node.type !== 'Atrule' || !node.block) {
284
+ if (node.type !== 'atrule' || !Array.isArray(node.nodes)) {
279
285
  return;
280
286
  }
281
- const name = String(node.name ?? '').toLowerCase();
282
- const prelude = generateNodeTextSimple(node.prelude);
287
+ const name = typeof node.name === 'string' ? node.name.toLowerCase() : '';
288
+ const prelude = generateNodeTextSimple(node.params);
283
289
  atruleStackForDecl.push({ name, prelude });
284
290
  }
285
291
  function pushRuleDeclStack(node) {
286
- if (node.type !== 'Rule' && node.type !== 'Atrule') {
292
+ if (node.type !== 'rule' && node.type !== 'atrule') {
287
293
  return;
288
294
  }
289
- if (!node.block?.children) {
295
+ if (!Array.isArray(node.nodes)) {
290
296
  return;
291
297
  }
292
- const name = node.type === 'Atrule' ? String(node.name ?? '').toLowerCase() : '';
293
- const prelude = node.type === 'Atrule' ? generateNodeTextSimple(node.prelude) : '';
298
+ const name = node.type === 'atrule' && typeof node.name === 'string' ? node.name.toLowerCase() : '';
299
+ const prelude = node.type === 'atrule' ? generateNodeTextSimple(node.params) : '';
294
300
  declStack.push({
295
301
  nodeType: node.type,
296
302
  name,
@@ -323,18 +329,15 @@ export function lintCssLikeStylelint(opts) {
323
329
  });
324
330
  }
325
331
  function processDeclaration(node) {
326
- if (node.type !== 'Declaration') {
332
+ if (node.type !== 'decl') {
327
333
  return;
328
334
  }
329
335
  const current = declStack[declStack.length - 1];
330
- const prop = String(node.property ?? '').toLowerCase();
331
- const value = node.value ? normalizeWhitespace(csstree.generate(node.value)) : '';
336
+ const prop = typeof node.prop === 'string' ? node.prop.toLowerCase() : '';
337
+ const value = typeof node.value === 'string' ? normalizeWhitespace(node.value) : '';
332
338
  const loc = node.loc?.start;
333
339
  checkImportant(node, loc);
334
340
  checkHttpUrl(value, loc);
335
- if (!current) {
336
- return;
337
- }
338
341
  const prev = current.seen.get(prop);
339
342
  if (!prev) {
340
343
  current.seen.set(prop, { value, line: loc?.line, column: loc?.column });
@@ -358,17 +361,17 @@ export function lintCssLikeStylelint(opts) {
358
361
  column: loc?.column
359
362
  });
360
363
  }
361
- csstree.walk(ast, {
364
+ walk(ast, {
362
365
  enter: (node) => {
363
366
  pushAtRuleDeclStack(node);
364
367
  pushRuleDeclStack(node);
365
368
  processDeclaration(node);
366
369
  },
367
370
  leave: (node) => {
368
- if ((node.type === 'Rule' || node.type === 'Atrule') && node.block?.children) {
371
+ if ((node.type === 'rule' || node.type === 'atrule') && Array.isArray(node.nodes)) {
369
372
  declStack.pop();
370
373
  }
371
- if (node.type === 'Atrule' && node.block) {
374
+ if (node.type === 'atrule' && Array.isArray(node.nodes)) {
372
375
  atruleStackForDecl.pop();
373
376
  }
374
377
  }
@@ -92,14 +92,14 @@ registerFormatter('.editorconfig', formatarEditorconfigMinimo);
92
92
  registerFormatter('.npmrc', formatarNpmrcMinimo);
93
93
  registerFormatter('.nvmrc', formatarNvmrcMinimo);
94
94
  registerFormatter('.json5', formatarJson5Minimo);
95
- registerFormatter('.ts', (code, relPath) => formatarTypeScriptMinimo(code, relPath ?? ''));
96
- registerFormatter('.tsx', (code, relPath) => formatarTypeScriptMinimo(code, relPath ?? ''));
97
- registerFormatter('.cts', (code, relPath) => formatarTypeScriptMinimo(code, relPath ?? ''));
98
- registerFormatter('.mts', (code, relPath) => formatarTypeScriptMinimo(code, relPath ?? ''));
99
- registerFormatter('.js', (code, relPath) => formatarJavaScriptMinimo(code, relPath ?? ''));
100
- registerFormatter('.jsx', (code, relPath) => formatarJavaScriptMinimo(code, relPath ?? ''));
101
- registerFormatter('.mjs', (code, relPath) => formatarJavaScriptMinimo(code, relPath ?? ''));
102
- registerFormatter('.cjs', (code, relPath) => formatarJavaScriptMinimo(code, relPath ?? ''));
95
+ registerFormatter('.ts', (code, relPath) => formatarTypeScriptMinimo(code, relPath));
96
+ registerFormatter('.tsx', (code, relPath) => formatarTypeScriptMinimo(code, relPath));
97
+ registerFormatter('.cts', (code, relPath) => formatarTypeScriptMinimo(code, relPath));
98
+ registerFormatter('.mts', (code, relPath) => formatarTypeScriptMinimo(code, relPath));
99
+ registerFormatter('.js', (code, relPath) => formatarJavaScriptMinimo(code, relPath));
100
+ registerFormatter('.jsx', (code, relPath) => formatarJavaScriptMinimo(code, relPath));
101
+ registerFormatter('.mjs', (code, relPath) => formatarJavaScriptMinimo(code, relPath));
102
+ registerFormatter('.cjs', (code, relPath) => formatarJavaScriptMinimo(code, relPath));
103
103
  export function getRegisteredFormatter(relPath) {
104
104
  return getFormatterForPath(relPath);
105
105
  }
@@ -16,7 +16,7 @@ export function getProtectedLinesFromTemplateLiterals(code, relPath) {
16
16
  try {
17
17
  const req = createRequire(import.meta.url);
18
18
  const parser = req('@babel/parser');
19
- const rp = (relPath ?? '').toLowerCase();
19
+ const rp = relPath.toLowerCase();
20
20
  const plugins = ['importMeta', 'dynamicImport', 'topLevelAwait', 'classProperties', 'classPrivateProperties', 'classPrivateMethods', 'classStaticBlock', 'optionalChaining', 'nullishCoalescingOperator', 'numericSeparator', 'logicalAssignment', 'privateIn', 'objectRestSpread', 'decorators-legacy'];
21
21
  const isTs = rp.endsWith('.ts') || rp.endsWith('.tsx') || rp.endsWith('.cts') || rp.endsWith('.mts');
22
22
  const isJsx = rp.endsWith('.jsx') || rp.endsWith('.tsx');
@@ -112,7 +112,7 @@ export function normalizarSeparadoresDeSecao(code, opts = {}) {
112
112
  if (!metrica) {
113
113
  continue;
114
114
  }
115
- const symbol = metrica[1] ?? '';
115
+ const symbol = metrica[1];
116
116
  if (!symbol) {
117
117
  continue;
118
118
  }
@@ -138,7 +138,7 @@ export function normalizarSeparadoresDeSecao(code, opts = {}) {
138
138
  if (!metrica) {
139
139
  return null;
140
140
  }
141
- const raw = (metrica[1] ?? '').trim();
141
+ const raw = (metrica[1]).trim();
142
142
  return {
143
143
  titulo: raw ? raw : null
144
144
  };
@@ -239,10 +239,6 @@ function parseCssTokens(tokenList) {
239
239
  let idx = 0;
240
240
  while (idx < tokenList.length) {
241
241
  const tok = tokenList[idx];
242
- if (!tok) {
243
- idx++;
244
- continue;
245
- }
246
242
  if (tok.kind === 'comment') {
247
243
  items.push({
248
244
  kind: 'comment',
@@ -261,10 +257,6 @@ function parseCssTokens(tokenList) {
261
257
  let depth = 1;
262
258
  while (idx < tokenList.length && depth > 0) {
263
259
  const innerTok = tokenList[idx];
264
- if (!innerTok) {
265
- idx++;
266
- continue;
267
- }
268
260
  if (innerTok.kind === 'text') {
269
261
  if (innerTok.value === '{') {
270
262
  depth++;
@@ -379,11 +371,11 @@ function renderCssItems(items, depth) {
379
371
  lines.push(`${indent(depth)}${item.prop}: ${item.value};`);
380
372
  }
381
373
  }
382
- else if (item.kind === 'block') {
374
+ else {
383
375
  // Add blank line before top-level blocks (except the first)
384
376
  if (depth === 0 && indice > 0) {
385
377
  const prevLine = lines[lines.length - 1];
386
- if (prevLine !== undefined && prevLine !== '') {
378
+ if (prevLine !== '') {
387
379
  lines.push('');
388
380
  }
389
381
  }
@@ -119,7 +119,7 @@ export function formatarEditorconfigMinimo(code) {
119
119
  const sectionMatch = trimmed.match(/^\[(.+)\]$/);
120
120
  if (sectionMatch) {
121
121
  flushSection();
122
- currentSection = sectionMatch[1].trim() ?? '';
122
+ currentSection = sectionMatch[1].trim();
123
123
  continue;
124
124
  }
125
125
  const eqIdx = trimmed.indexOf('=');
@@ -31,7 +31,7 @@ function parseTagAttributes(tagContent) {
31
31
  if (!name) {
32
32
  continue;
33
33
  }
34
- const value = metrica[2] ?? metrica[3] ?? metrica[4] ?? '';
34
+ const value = metrica[2] || metrica[3] || metrica[4] || '';
35
35
  attrs.push({
36
36
  name,
37
37
  value
@@ -358,10 +358,6 @@ export function formatarHtmlMinimo(code) {
358
358
  let indice = 0;
359
359
  while (indice < tokens.length) {
360
360
  const tok = tokens[indice];
361
- if (!tok) {
362
- indice++;
363
- continue;
364
- }
365
361
  if (tok.kind === 'comment') {
366
362
  const commentLines = tok.value.trim().split('\n');
367
363
  for (const cl of commentLines) {
@@ -28,9 +28,6 @@ function tentarRecuperarJson(input) {
28
28
  let escaped = false;
29
29
  for (let indice = 0; indice < code.length; indice++) {
30
30
  const ch = code[indice];
31
- if (ch === undefined) {
32
- break;
33
- }
34
31
  if (escaped) {
35
32
  comAspasDuplas += ch;
36
33
  escaped = false;
@@ -6,8 +6,8 @@ export function matchMarkdownFence(line) {
6
6
  if (!metrica) {
7
7
  return null;
8
8
  }
9
- const ch = (metrica[1] ?? '`') === '~' ? '~' : '`';
10
- const len = (metrica[0] ?? '').length;
9
+ const ch = (metrica[1]) === '~' ? '~' : '`';
10
+ const len = metrica[0].length;
11
11
  const rest = trimmedLeft.slice(len);
12
12
  return {
13
13
  ch,
@@ -31,8 +31,8 @@ function normalizarCercasMarkdown(code, protectedLines) {
31
31
  }
32
32
  const typo = line.match(/^(\s*)``è(.*)$/);
33
33
  if (typo) {
34
- const prefix = typo[1] ?? '';
35
- const after = typo[2] ?? '';
34
+ const prefix = typo[1];
35
+ const after = typo[2];
36
36
  const normalized = `${prefix}\`\`\`${after}`;
37
37
  if (normalized !== line) {
38
38
  changed = true;
@@ -43,16 +43,16 @@ function normalizarCercasMarkdown(code, protectedLines) {
43
43
  if (!metrica) {
44
44
  return line;
45
45
  }
46
- const prefix = metrica[1] ?? '';
47
- const fence = metrica[2] ?? '';
48
- const afterFence = metrica[3] ?? '';
46
+ const prefix = metrica[1];
47
+ const fence = metrica[2];
48
+ const afterFence = metrica[3];
49
49
  const info = afterFence.match(/^(\s*)(\S+)(.*)$/);
50
50
  if (!info) {
51
51
  return line;
52
52
  }
53
- const lead = info[1] ?? '';
54
- const token = info[2] ?? '';
55
- const tail = info[3] ?? '';
53
+ const lead = info[1];
54
+ const token = info[2];
55
+ const tail = info[3];
56
56
  const shouldNormalizeToken = /[^\x00-\x7F]/.test(token);
57
57
  if (!shouldNormalizeToken) {
58
58
  return line;
@@ -92,6 +92,7 @@ function corrigirHtmlInlineEmMarkdown(text, _protectedLines) {
92
92
  function corrigirEnfaseMarkdown(text) {
93
93
  let changed = false;
94
94
  let out = text;
95
+ let current = text;
95
96
  // Não corrigir ênfase em itens de lista markdown (podem ter sintaxe ambígua intencional)
96
97
  if (/^\s*[-*+]\s/.test(out)) {
97
98
  return {
@@ -103,10 +104,10 @@ function corrigirEnfaseMarkdown(text) {
103
104
  out = out.replace(/\*\*\*([^\s*][^*\n]*?)\*\*\*(?!\*)/g, '**$1**');
104
105
  out = out.replace(/(^|[^*])\*([^\s*][^*\n]*?)\*\*(?!\*)/g, '$1*$2*');
105
106
  out = out.replace(/(^|[^*])\*([^\s*][^*\n]*?)\*\*\*(?!\*)/g, '$1*$2*');
106
- if (out !== text) {
107
+ if (out !== current) {
107
108
  changed = true;
108
109
  }
109
- text = out;
110
+ current = out;
110
111
  const encontrarFimEnfase = (texto) => {
111
112
  // Heurísticas para encontrar onde a ênfase deve terminar:
112
113
  // 1. Se há vírgula seguida de espaço, pode indicar fim da ênfase
@@ -121,7 +122,7 @@ function corrigirEnfaseMarkdown(text) {
121
122
  const antes = texto.slice(0, pontuacaoForte.index);
122
123
  const ultimaPalavra = antes.match(/(\S+)$/);
123
124
  if (ultimaPalavra) {
124
- const palavra = ultimaPalavra[1]?.toLowerCase();
125
+ const palavra = ultimaPalavra[1].toLowerCase();
125
126
  if (palavra) {
126
127
  const abreviacoes = ['sr', 'sra', 'dr', 'dra', 'prof', 'etc', 'ex', 'vs', 'aprox', 'obs', 'v', 'p', 'n', 'e'];
127
128
  if (!abreviacoes.includes(palavra.replace(/[.!?]+$/, ''))) {
@@ -163,9 +164,6 @@ function corrigirEnfaseMarkdown(text) {
163
164
  return str;
164
165
  }
165
166
  const ultimoIdx = posicoes[posicoes.length - 1];
166
- if (ultimoIdx === undefined) {
167
- return str;
168
- }
169
167
  // Não corrigir se o marcador órfão está no início ou fim da linha (pode ser intencional)
170
168
  if (ultimoIdx === 0 || ultimoIdx + len >= str.trimEnd().length) {
171
169
  return str;
@@ -212,9 +210,6 @@ function corrigirEnfaseMarkdown(text) {
212
210
  return str;
213
211
  }
214
212
  const ultimoIdx = posicoes[posicoes.length - 1];
215
- if (ultimoIdx === undefined) {
216
- return str;
217
- }
218
213
  // Não corrigir se o marcador órfão está no início ou fim da linha (pode ser intencional)
219
214
  if (ultimoIdx === 0 || ultimoIdx + len >= str.trimEnd().length) {
220
215
  return str;
@@ -250,7 +245,7 @@ function corrigirEnfaseMarkdown(text) {
250
245
  return raiz;
251
246
  });
252
247
  out = corrigidas.join('\n');
253
- if (out !== text) {
248
+ if (out !== current) {
254
249
  changed = true;
255
250
  }
256
251
  return {
@@ -366,8 +361,8 @@ function assegurarLinhaVaziaAposTitulosMarkdown(code) {
366
361
  out.push(line);
367
362
  const ehHeading = /^#{1,6}\s+\S/.test(line.trim());
368
363
  const proxima = lines[indice + 1];
369
- const proximaTambemHeading = proxima !== undefined && /^#{1,6}\s+\S/.test(proxima.trim());
370
- const precisaEspaco = ehHeading && proxima !== undefined && proxima.trim() !== '' && !proximaTambemHeading;
364
+ const proximaTambemHeading = typeof proxima === 'string' && /^#{1,6}\s+\S/.test(proxima.trim());
365
+ const precisaEspaco = ehHeading && typeof proxima === 'string' && proxima.trim() !== '' && !proximaTambemHeading;
371
366
  if (precisaEspaco) {
372
367
  out.push('');
373
368
  changed = true;
@@ -408,8 +403,8 @@ function formatarListasMarkdown(code) {
408
403
  }
409
404
  const listMatch = line.match(/^(\s*)([*+\-])\s+(.*)$/);
410
405
  if (listMatch) {
411
- const indent = listMatch[1] ?? '';
412
- const content = listMatch[3] ?? '';
406
+ const indent = listMatch[1];
407
+ const content = listMatch[3];
413
408
  const normalized = `${indent}- ${content}`;
414
409
  if (normalized !== line) {
415
410
  changed = true;
@@ -41,8 +41,8 @@ function parsePropertiesLines(code) {
41
41
  // Key-value com separador := ou =
42
42
  const sepMatch = trimmed.match(/^([^:=]+?)\s*[:=]\s*(.*)$/);
43
43
  if (sepMatch) {
44
- const key = (sepMatch[1] ?? '').trim();
45
- const val = (sepMatch[2] ?? '').trim();
44
+ const key = sepMatch[1].trim();
45
+ const val = sepMatch[2].trim();
46
46
  const isContinuation = val.endsWith('\\');
47
47
  if (isContinuation) {
48
48
  inContinuation = true;
@@ -42,9 +42,6 @@ function parseShellLine(raw, ctx) {
42
42
  let indice = 0;
43
43
  while (indice < trimmed.length) {
44
44
  const ch = trimmed[indice];
45
- if (ch === undefined) {
46
- break;
47
- }
48
45
  if (escaped) {
49
46
  escaped = false;
50
47
  indice++;
@@ -94,7 +91,7 @@ function parseShellLine(raw, ctx) {
94
91
  const rest = trimmed.slice(indice);
95
92
  const hereDocMatch = rest.match(/<<-?\s*['"]?(\w+)['"]?/);
96
93
  if (hereDocMatch) {
97
- const delimiter = hereDocMatch[1] ?? '';
94
+ const delimiter = hereDocMatch[1];
98
95
  const stripTabs = rest.includes('<<-');
99
96
  return {
100
97
  output: trimmed,
@@ -140,9 +140,6 @@ export function formatarSqlMinimo(code) {
140
140
  };
141
141
  for (let textoTitulo = 0; textoTitulo < tokens.length; textoTitulo++) {
142
142
  const tok = tokens[textoTitulo];
143
- if (!tok) {
144
- continue;
145
- }
146
143
  // comments always on their own line
147
144
  if (tok.type === 'comment') {
148
145
  if (!lineStart) {
@@ -1,12 +1,11 @@
1
1
  // SPDX-License-Identifier: MIT
2
- import { XMLValidator } from 'fast-xml-parser';
3
2
  import { corrigirPontuacaoECodigo, normalizarFimDeLinha, normalizarNewlinesFinais, removerBom, removerEspacosFinaisPorLinha } from './commons.js';
4
3
  function tokenizeXml(src) {
5
4
  const re = /(<\?[\s\S]*?\?>|<!--[\s\S]*?-->|<!\[CDATA\[[\s\S]*?\]\]>|<!DOCTYPE[\s\S]*?>|<\/?[^>\n]+?>)/gi;
6
5
  const out = [];
7
6
  let last = 0;
8
7
  for (const metrica of src.matchAll(re)) {
9
- const start = metrica.index ?? -1;
8
+ const start = metrica.index;
10
9
  if (start < 0) {
11
10
  continue;
12
11
  }
@@ -18,9 +17,9 @@ function tokenizeXml(src) {
18
17
  }
19
18
  out.push({
20
19
  kind: 'tag',
21
- value: metrica[0] ?? ''
20
+ value: metrica[0]
22
21
  });
23
- last = start + (metrica[0].length ?? 0);
22
+ last = start + metrica[0].length;
24
23
  }
25
24
  if (last < src.length) {
26
25
  out.push({
@@ -174,12 +173,11 @@ export function formatarXmlMinimo(code) {
174
173
  return raiz.tag;
175
174
  }).join('');
176
175
  let pretty = rebuilt;
177
- const valid = XMLValidator.validate(pretty);
178
- if (valid === true) {
176
+ try {
179
177
  const pp = prettyPrintXmlIfSafe(pretty);
180
178
  pretty = pp.xml;
181
179
  }
182
- else {
180
+ catch {
183
181
  pretty = `${pretty.trimEnd()}\n`;
184
182
  }
185
183
  const formatted = normalizarNewlinesFinais(pretty);
@@ -230,7 +230,7 @@ function corrigirChavesDuplicadas(lines) {
230
230
  if (line.kind === 'mapping') {
231
231
  const keyMatch = line.content.match(/^([^:]+):/);
232
232
  if (keyMatch) {
233
- const key = (keyMatch[1] ?? '').trim();
233
+ const key = keyMatch[1].trim();
234
234
  if (seenKeys.has(key)) {
235
235
  const count = (seenKeys.get(key) ?? 0) + 1;
236
236
  warnings.push(`Chave duplicada "${key}" na linha ${(seenKeys.get(key) ?? 0) + 1} e ${out.length + 1}`);
@@ -253,18 +253,13 @@ function corrigirStringsMultilineYaml(lines) {
253
253
  let indice = 0;
254
254
  while (indice < lines.length) {
255
255
  const line = lines[indice];
256
- if (line === undefined) {
257
- break;
258
- }
259
256
  if (line.kind === 'multiline-start') {
260
257
  out.push(line);
261
258
  indice++;
262
259
  const contentLines = [];
263
260
  while (indice < lines.length && (lines[indice]?.kind === 'multiline-content' || lines[indice]?.kind === 'empty')) {
264
261
  const cl = lines[indice];
265
- if (cl) {
266
- contentLines.push(cl);
267
- }
262
+ contentLines.push(cl);
268
263
  indice++;
269
264
  }
270
265
  if (contentLines.length > 0) {
@@ -23,7 +23,7 @@ export function formatarCodeMinimo(code, opts) {
23
23
  const formatted = normalizarNewlinesFinais(removerEspacosFinaisPorLinha(normalized));
24
24
  return {
25
25
  ok: true,
26
- parser: opts?.parser ?? 'code',
26
+ parser: (opts?.parser ?? 'code'),
27
27
  formatted,
28
28
  changed: formatted !== normalizarNewlinesFinais(normalized),
29
29
  };
@@ -9,7 +9,11 @@ export function detectarFrameworks(rootDir) {
9
9
  try {
10
10
  const packageJsonCaminho = path.join(rootDir, 'package.json');
11
11
  const packageJsonRaw = fs.readFileSync(packageJsonCaminho, 'utf-8');
12
- const packageJson = JSON.parse(packageJsonRaw);
12
+ const parsedJson = JSON.parse(packageJsonRaw);
13
+ if (typeof parsedJson !== 'object' || parsedJson === null) {
14
+ return frameworks;
15
+ }
16
+ const packageJson = parsedJson;
13
17
  const dependencies = packageJson.dependencies ?? {};
14
18
  const devDependencies = packageJson.devDependencies ?? {};
15
19
  // Lista de frameworks conhecidos com seus identificadores
@@ -69,7 +73,7 @@ export function detectarFrameworks(rootDir) {
69
73
  }
70
74
  // Remover duplicatas (mesma framework em prod e dev)
71
75
  const unique = frameworks.reduce((acc, curr) => {
72
- if (!acc.find(arquivo => arquivo.name === curr.name)) {
76
+ if (!acc?.find(arquivo => arquivo.name === curr.name)) {
73
77
  acc.push(curr);
74
78
  }
75
79
  return acc;
@@ -24,7 +24,7 @@ export function escapeNonAscii(string) {
24
24
  let out = '';
25
25
  for (const ch of string) {
26
26
  const cp = ch.codePointAt(0);
27
- if (cp === undefined || cp === null || cp <= ASCII_MAX) {
27
+ if (cp === undefined || cp <= ASCII_MAX) {
28
28
  out += ch;
29
29
  }
30
30
  else if (cp <= BMP_MAX) {
@@ -155,7 +155,7 @@ export function isWhitelistedConstant(value, frameworks, userWhitelist) {
155
155
  */
156
156
  export function getConstantDescription(value, frameworks) {
157
157
  // Verificar todas as whitelists
158
- const allRules = [...MATH_CONSTANTES, ...COMUM_LIMITES, ...HTTP_STATUS_CODIGOS, ...frameworks.flatMap(arquivo => FRAMEWORK_WHITELISTS[arquivo] || [])];
158
+ const allRules = [...MATH_CONSTANTES, ...COMUM_LIMITES, ...HTTP_STATUS_CODIGOS, ...frameworks.flatMap(arquivo => FRAMEWORK_WHITELISTS[arquivo] ?? [])];
159
159
  const rule = allRules.find(raiz => raiz.value === value);
160
160
  return rule?.description;
161
161
  }