diff --git a/lib/anonymize.js b/lib/anonymize.js index 2ef924e69..dd5b75923 100644 --- a/lib/anonymize.js +++ b/lib/anonymize.js @@ -4,18 +4,11 @@ so that the CLI tests (in the `test/` folder) have the same output on different machines, and also the same output when only the CLI version changes. */ -const path = require('node:path'); - /** - * @import {Options} from "./types/options" - * @import {Path} from "./types/path" + * @import {Options} from './types/options'; + * @import {Path} from './types/path'; */ - -module.exports = { - pathsAndVersions, - path: anonymizePath, - version -}; +const path = require('node:path'); /** * Strip the version and paths out of the given string. @@ -75,3 +68,9 @@ function version(options) { return options.packageJsonVersion; } + +module.exports = { + pathsAndVersions, + path: anonymizePath, + version +}; diff --git a/lib/app-wrapper.js b/lib/app-wrapper.js index 177dbd552..d584fbea1 100644 --- a/lib/app-wrapper.js +++ b/lib/app-wrapper.js @@ -1,25 +1,13 @@ -const path = require('node:path'); -const {Worker} = require('node:worker_threads'); -const ElmCommunication = require('./elm-communication'); -const loadCompiledElmApp = require('./load-compiled-app'); - /** * @import {Options} from './types/options' * @import {CallbackFn, Listened, Port} from './types/promisify-port' * @import {Flags} from './types/flags' * @import {App} from './types/app' */ - -module.exports = { - init, - stop: () => { - if (worker) { - worker.terminate(); - worker = null; - listeners = initializeListeners(); - } - } -}; +const path = require('node:path'); +const {Worker} = require('node:worker_threads'); +const ElmCommunication = require('./elm-communication'); +const loadCompiledElmApp = require('./load-compiled-app'); /** * @param {Options} options @@ -157,3 +145,16 @@ function initWithoutWorker(elmModulePath, flags) { }); return app; } + +function stop() { + if (worker) { + worker.terminate(); + worker = null; + listeners = initializeListeners(); + } +} + +module.exports = { + init, + stop +}; diff --git a/lib/autofix.js b/lib/autofix.js index f2d455478..597f8e766 100644 --- a/lib/autofix.js +++ b/lib/autofix.js @@ -1,30 +1,25 @@ +/** + * @import {App, AutofixRequest} from './types/app'; + * @import {File} from './types/content'; + * @import {VersionString} from './types/version'; + * @import {Options} from './types/options'; + * @import {Path} from './types/path'; + * @import {FilesProposedByCurrentFix} from './types/state'; + */ const fs = require('node:fs'); const path = require('node:path'); const chalk = require('chalk'); -const prompts = require('prompts'); const spawn = require('cross-spawn'); -const FS = require('./fs-wrapper'); -const AppState = require('./state'); +const prompts = require('prompts'); +const exit = require('../vendor/exit'); const ErrorMessage = require('./error-message'); +const FS = require('./fs-wrapper'); +const {backwardsCompatiblePath, pathKey} = require('./npx'); +const ProjectDependencies = require('./project-dependencies'); const promisifyPort = require('./promisify-port'); -const StyledMessage = require('./styled-message'); const {startReview} = require('./run-review'); -const ProjectDependencies = require('./project-dependencies'); -const exit = require('../vendor/exit'); -const {backwardsCompatiblePath, pathKey} = require('./npx'); - -/** - * @import {App, AutofixRequest} from "./types/app" - * @import {File} from "./types/content" - * @import {VersionString} from "./types/version" - * @import {Options} from "./types/options" - * @import {Path} from "./types/path" - * @import {FilesProposedByCurrentFix} from "./types/state" - */ - -module.exports = { - subscribe -}; +const AppState = require('./state'); +const StyledMessage = require('./styled-message'); /** * Subscribe to fix requests to prompt the user. @@ -237,3 +232,7 @@ ${result.stderr.toString()}`, source: fs.readFileSync(filePath, 'utf8') }; } + +module.exports = { + subscribe +}; diff --git a/lib/benchmark.js b/lib/benchmark.js index bd9b88400..322df6be2 100644 --- a/lib/benchmark.js +++ b/lib/benchmark.js @@ -1,12 +1,7 @@ /** - * @import {OptionsBase} from "./types/options" + * @import {OptionsBase} from './types/options'; */ -module.exports = { - start, - end -}; - /** * Start a benchmark labelled with the given name. * @@ -32,3 +27,8 @@ function end(options, name) { console.timeEnd(name); } } + +module.exports = { + start, + end +}; diff --git a/lib/build.js b/lib/build.js index 71f23883b..40e563bab 100644 --- a/lib/build.js +++ b/lib/build.js @@ -1,31 +1,30 @@ -const fs = require('graceful-fs'); +/** + * @import {AppHash, BuildResult} from './types/build'; + * @import {ApplicationElmJson} from './types/content'; + * @import {VersionString} from './types/version'; + * @import {Options, Template} from './types/options'; + * @import {Path} from './types/path'; + * @import {CompileOptions} from '../vendor/types/node-elm-compiler'; + */ const path = require('node:path'); const crypto = require('node:crypto'); const chalk = require('chalk'); -const wrap = require('wrap-ansi'); const {hashElement} = require('folder-hash'); +const fs = require('graceful-fs'); +const wrap = require('wrap-ansi'); +const exit = require('../vendor/exit'); const elmCompiler = require('../vendor/node-elm-compiler'); -const {getElmBinary} = require('./elm-binary'); -const Debug = require('./debug'); -const FS = require('./fs-wrapper'); -const Spinner = require('./spinner'); const Anonymize = require('./anonymize'); const Benchmark = require('./benchmark'); -const OptimizeJs = require('./optimize-js'); -const MinVersion = require('./min-version'); +const Debug = require('./debug'); +const {getElmBinary} = require('./elm-binary'); const ErrorMessage = require('./error-message'); +const FS = require('./fs-wrapper'); +const MinVersion = require('./min-version'); +const OptimizeJs = require('./optimize-js'); const RemoteTemplate = require('./remote-template'); +const Spinner = require('./spinner'); const TemplateDependencies = require('./template-dependencies'); -const exit = require('../vendor/exit'); - -/** - * @import {AppHash, BuildResult} from "./types/build" - * @import {ApplicationElmJson} from "./types/content" - * @import {VersionString} from "./types/version" - * @import {Options, Template} from "./types/options" - * @import {Path} from "./types/path" - * @import {CompileOptions} from "../vendor/types/node-elm-compiler" - */ const templateSrc = path.join(__dirname, '../template/src'); const parseElmFolder = path.join(__dirname, '../parseElm'); diff --git a/lib/cache.js b/lib/cache.js index 444cc63b5..6e3018bb7 100644 --- a/lib/cache.js +++ b/lib/cache.js @@ -1,11 +1,10 @@ +/** + * @import {Path} from './types/path'; + */ const path = require('node:path'); const FS = require('./fs-wrapper'); const AppState = require('./state'); -/** - * @import {Path} from "./types/path" - */ - /** * @template {object} T * @param {Path} folder diff --git a/lib/debug.js b/lib/debug.js index 7973870a9..275384965 100644 --- a/lib/debug.js +++ b/lib/debug.js @@ -2,10 +2,6 @@ const AppState = require('./state'); const options = AppState.getOptions(); -module.exports = { - log -}; - /** * @param {string} message */ @@ -14,3 +10,7 @@ function log(message) { console.log(message); } } + +module.exports = { + log +}; diff --git a/lib/dependency-provider.js b/lib/dependency-provider.js index f7c48737d..2386e5853 100644 --- a/lib/dependency-provider.js +++ b/lib/dependency-provider.js @@ -1,15 +1,14 @@ -const fs = require('graceful-fs'); +/** + * @import {Options} from './types/options'; + * @import {Path} from './types/path'; + * @import {VersionString} from './types/version'; + */ const path = require('node:path'); const wasm = require('elm-solve-deps-wasm'); +const fs = require('graceful-fs'); const FS = require('./fs-wrapper'); -const SyncGet = require('./sync-get'); const ProjectJsonFiles = require('./project-json-files'); - -/** - * @import {Options} from "./types/options" - * @import {Path} from "./types/path" - * @import {VersionString} from "./types/version" - */ +const SyncGet = require('./sync-get'); /** @type {boolean} */ let wasmWasInitialized = false; diff --git a/lib/elm-app-worker.js b/lib/elm-app-worker.js index 4a3c1e325..2db9c1f31 100644 --- a/lib/elm-app-worker.js +++ b/lib/elm-app-worker.js @@ -1,12 +1,11 @@ +/** + * @import {MessagePort} from 'worker_threads'; + */ const {parentPort, workerData} = require('node:worker_threads'); const ElmCommunication = require('./elm-communication'); const loadCompiledElmApp = require('./load-compiled-app'); const ResultCache = require('./result-cache'); -/** - * @import {MessagePort} from "worker_threads" - */ - const elmModule = loadCompiledElmApp(workerData.elmModulePath); const app = elmModule.Elm.Elm.Review.Main.init({ diff --git a/lib/elm-binary.js b/lib/elm-binary.js index 26b0ef07e..73f0b578d 100644 --- a/lib/elm-binary.js +++ b/lib/elm-binary.js @@ -1,16 +1,15 @@ +/** + * @import {Options} from './types/options'; + * @import {Path} from './types/path'; + * @import {VersionString} from './types/version'; + */ const path = require('node:path'); const chalk = require('chalk'); -const which = require('which'); const spawn = require('cross-spawn'); +const which = require('which'); const ErrorMessage = require('./error-message'); const {backwardsCompatiblePath} = require('./npx'); -/** - * @import {Options} from "./types/options" - * @import {Path} from "./types/path" - * @import {VersionString} from "./types/version" - */ - /** * Get the path to the Elm binary * diff --git a/lib/elm-communication.js b/lib/elm-communication.js index c2cebc707..3c84288a4 100644 --- a/lib/elm-communication.js +++ b/lib/elm-communication.js @@ -1,13 +1,8 @@ -const Debug = require('./debug'); -const Benchmark = require('./benchmark'); - /** - * @import {Flags} from "./types/flags" + * @import {Flags} from './types/flags'; */ - -module.exports = { - create -}; +const Benchmark = require('./benchmark'); +const Debug = require('./debug'); let hasWrittenThings = false; @@ -77,3 +72,7 @@ function create(options) { } ); } + +module.exports = { + create +}; diff --git a/lib/elm-files.js b/lib/elm-files.js index cd4b74ff0..cc2f9c01e 100644 --- a/lib/elm-files.js +++ b/lib/elm-files.js @@ -1,22 +1,21 @@ +/** + * @import {ElmFile, Source, Readme, ElmJson, ElmJsonData, SourceDirectories} from './types/content'; + * @import {ReviewOptions} from './types/options'; + * @import {Path} from './types/path'; + */ const path = require('node:path'); -const {glob} = require('glob'); const chalk = require('chalk'); -const Hash = require('./hash'); +const {glob} = require('glob'); +const Anonymize = require('./anonymize'); +const Benchmark = require('./benchmark'); +const Cache = require('./cache'); const Debug = require('./debug'); +const ErrorMessage = require('./error-message'); const FS = require('./fs-wrapper'); -const Benchmark = require('./benchmark'); -const Anonymize = require('./anonymize'); +const Hash = require('./hash'); +const OsHelpers = require('./os-helpers'); const elmParser = require('./parse-elm'); const AppState = require('./state'); -const OsHelpers = require('./os-helpers'); -const ErrorMessage = require('./error-message'); -const Cache = require('./cache'); - -/** - * @import {ElmFile, Source, Readme, ElmJson, ElmJsonData, SourceDirectories} from "./types/content" - * @import {ReviewOptions} from "./types/options" - * @import {Path} from "./types/path" - */ const defaultGlob = '**/*.elm$'; diff --git a/lib/error-message.js b/lib/error-message.js index 3824257bb..77c8378b5 100644 --- a/lib/error-message.js +++ b/lib/error-message.js @@ -1,12 +1,11 @@ +/** + * @import {Options} from './types/options'; + * @import {Path} from './types/path'; + */ const chalk = require('chalk'); const stripAnsi = require('strip-ansi'); const Anonymize = require('./anonymize'); -/** - * @import {Options} from "./types/options" - * @import {Path} from "./types/path" - */ - class CustomError extends Error { /** * @param {string} title diff --git a/lib/extra-files.js b/lib/extra-files.js index f992e9dfd..d5d3cfc95 100644 --- a/lib/extra-files.js +++ b/lib/extra-files.js @@ -1,12 +1,8 @@ -const FS = require('./fs-wrapper'); -const OsHelpers = require('./os-helpers'); - /** - * @import {ExtraFileRequest, NonElmFiles} from "./types/content" + * @import {ExtraFileRequest, NonElmFiles} from './types/content'; */ - -// microsoft/TypeScript#58955 -/** @typedef {import("globby", {with: {'resolution-mode': 'import'}}).globby} globby */ +const FS = require('./fs-wrapper'); +const OsHelpers = require('./os-helpers'); /** * Collect the extra files requested by the rules. @@ -15,9 +11,8 @@ const OsHelpers = require('./os-helpers'); * @returns {Promise} */ async function collect(requests) { - const {globby} = await import('globby'); const files2D = await Promise.all( - requests.map((request) => getFiles(globby, request)) + requests.map((request) => getFiles(request)) ); const flatFiles = files2D.flat(); const files = unique(flatFiles); @@ -38,12 +33,13 @@ async function collect(requests) { } /** - * @param {globby} globby * @param {ExtraFileRequest} request * @returns {Promise} */ -function getFiles(globby, request) { - return globby( +async function getFiles(request) { + const {globby} = await import('globby'); + + return await globby( request.files.map( (file) => `${file.included ? '' : '!'}${OsHelpers.makePathOsAgnostic( diff --git a/lib/flags.js b/lib/flags.js index 47a7b29f8..2cbed8246 100644 --- a/lib/flags.js +++ b/lib/flags.js @@ -1,9 +1,8 @@ -const chalk = require('chalk'); - /** - * @import {Flag, Section} from "./types/flag" - * @import {Subcommand} from "./types/options" + * @import {Flag, Section} from './types/flag'; + * @import {Subcommand} from './types/options'; */ +const chalk = require('chalk'); const orange = chalk.keyword('orange'); diff --git a/lib/fs-wrapper.js b/lib/fs-wrapper.js index aa4a4388b..c448cb50c 100644 --- a/lib/fs-wrapper.js +++ b/lib/fs-wrapper.js @@ -1,12 +1,11 @@ +/** + * @import {Path} from './types/path'; + * @import {Replacer, Reviver} from './types/json'; + */ const fs = require('graceful-fs'); const fsp = fs.promises; const {rimraf} = require('rimraf'); -/** - * @import {Path} from "./types/path" - * @import {Replacer, Reviver} from "./types/json" - */ - /** * Read a JSON file. * diff --git a/lib/hash.js b/lib/hash.js index 6e8d4785c..db7c5b98b 100644 --- a/lib/hash.js +++ b/lib/hash.js @@ -1,7 +1,5 @@ const crypto = require('node:crypto'); -module.exports = {hash}; - /** * Hash a string. * @@ -11,3 +9,7 @@ module.exports = {hash}; function hash(content) { return crypto.createHash('md5').update(content).digest('hex'); } + +module.exports = { + hash +}; diff --git a/lib/help.js b/lib/help.js index ec98d869b..f46d83bf3 100644 --- a/lib/help.js +++ b/lib/help.js @@ -1,10 +1,9 @@ -const chalk = require('chalk'); -const Flags = require('./flags'); -const Anonymize = require('./anonymize'); - /** - * @import {Options} from "./types/options" + * @import {Options} from './types/options'; */ +const chalk = require('chalk'); +const Anonymize = require('./anonymize'); +const Flags = require('./flags'); /** * @param {Options} options diff --git a/lib/init.js b/lib/init.js index e2bebbde5..11dd18a26 100644 --- a/lib/init.js +++ b/lib/init.js @@ -1,5 +1,5 @@ -const fs = require('graceful-fs'); const path = require('node:path'); +const fs = require('graceful-fs'); // TODO(@lishaduck) [engine:node@>=16.7.0]: Use native `cp`. const fsExtra = require('fs-extra'); const chalk = require('chalk'); @@ -10,12 +10,6 @@ const RemoteTemplate = require('./remote-template'); const {getElmBinary, getElmVersion} = require('./elm-binary'); const TemplateDependencies = require('./template-dependencies'); -module.exports = { - create, - createFromTemplate, - promptAndCreate -}; - async function promptAndCreate(options) { const directory = options.initPath(); @@ -161,3 +155,9 @@ function createReviewConfig(directory, template) { path.join(directory, 'ReviewConfig.elm') ); } + +module.exports = { + create, + createFromTemplate, + promptAndCreate +}; diff --git a/lib/load-compiled-app.js b/lib/load-compiled-app.js index ad84dfef8..5b9407fa5 100644 --- a/lib/load-compiled-app.js +++ b/lib/load-compiled-app.js @@ -1,9 +1,8 @@ -const path = require('node:path'); - /** - * @import {Path} from "./types/path" - * @import {Elm} from "./types/app" + * @import {Path} from './types/path'; + * @import {Elm} from './types/app'; */ +const path = require('node:path'); module.exports = loadCompiledElmApp; diff --git a/lib/main.js b/lib/main.js index 0a57c22d8..db8e1c792 100644 --- a/lib/main.js +++ b/lib/main.js @@ -9,28 +9,27 @@ if (!process.argv.includes('--no-color')) { } } +/** + * @import {Options, ReviewOptions} from './types/options'; + */ const path = require('node:path'); const chalk = require('chalk'); -const Help = require('./help'); -const Init = require('./init'); -const Builder = require('./build'); -const Runner = require('./runner'); -const AppState = require('./state'); -const Spinner = require('./spinner'); -const NewRule = require('./new-rule'); +const exit = require('../vendor/exit'); const Anonymize = require('./anonymize'); -const NewPackage = require('./new-package'); const AppWrapper = require('./app-wrapper'); +const Builder = require('./build'); const ElmBinary = require('./elm-binary'); -const ResultCache = require('./result-cache'); const ErrorMessage = require('./error-message'); +const Help = require('./help'); +const Init = require('./init'); +const NewPackage = require('./new-package'); +const NewRule = require('./new-rule'); +const ResultCache = require('./result-cache'); +const Runner = require('./runner'); +const Spinner = require('./spinner'); +const AppState = require('./state'); const SuppressedErrors = require('./suppressed-errors'); const Watch = require('./watch'); -const exit = require('../vendor/exit'); - -/** - * @import {Options, ReviewOptions} from "./types/options" - */ /** * @type {Options} diff --git a/lib/min-version.js b/lib/min-version.js index 66c28fcbf..44bad626b 100644 --- a/lib/min-version.js +++ b/lib/min-version.js @@ -1,25 +1,17 @@ +/** + * @import {Options} from './types/options'; + * @import {Path} from './types/path'; + * @import {VersionString} from './types/version'; + */ const path = require('node:path'); const chalk = require('chalk'); -const PathHelpers = require('./path-helpers'); const ErrorMessage = require('./error-message'); - -/** - * @import {Options} from "./types/options" - * @import {Path} from "./types/path" - * @import {VersionString} from "./types/version" - */ +const PathHelpers = require('./path-helpers'); const minimalVersion = {major: 2, minor: 14}; // prettier-ignore const supportedRange = `${minimalVersion.major}.${minimalVersion.minor}.0 <= v < ${minimalVersion.major + 1}.0.0` -module.exports = { - updateToAtLeastMinimalVersion, - validate, - minimalVersion, - supportedRange -}; - /** * If given an input version string smaller than the hardcoded `minimalVersion`, * it will return the minimal version. @@ -97,3 +89,10 @@ cd ${dirPath} npx elm-json upgrade --unsafe`)}` ); } + +module.exports = { + updateToAtLeastMinimalVersion, + validate, + minimalVersion, + supportedRange +}; diff --git a/lib/module-cache.js b/lib/module-cache.js index cf3510c02..e18063bc7 100644 --- a/lib/module-cache.js +++ b/lib/module-cache.js @@ -1,14 +1,13 @@ +/** + * @import {Options} from './types/options'; + * @import {App} from './types/app'; + * @import {Ast} from './types/content'; + */ const path = require('node:path'); const AppState = require('./state'); const Hash = require('./hash'); const Cache = require('./cache'); -/** - * @import {Options} from "./types/options" - * @import {App} from "./types/app" - * @import {Ast} from "./types/content"; - */ - /** * @param {Options} options * @param {App} app diff --git a/lib/new-package.js b/lib/new-package.js index 712a0475e..49d34b2e5 100644 --- a/lib/new-package.js +++ b/lib/new-package.js @@ -1,19 +1,18 @@ -const path = require('node:path'); +/** + * @import {ElmJson} from './types/content'; + */ const childProcess = require('node:child_process'); +const path = require('node:path'); const chalk = require('chalk'); -const prompts = require('prompts'); // TODO(@lishaduck) [engine:node@>=16.7.0]: Use native `cp`. const fsExtra = require('fs-extra'); -const Init = require('./init'); -const Spinner = require('./spinner'); -const NewRule = require('./new-rule'); +const prompts = require('prompts'); +const ErrorMessage = require('./error-message'); const FS = require('./fs-wrapper'); +const Init = require('./init'); const MinVersion = require('./min-version'); -const ErrorMessage = require('./error-message'); - -/** - * @import {ElmJson} from "./types/content" - */ +const NewRule = require('./new-rule'); +const Spinner = require('./spinner'); async function create(options) { const onCancelOptions = { diff --git a/lib/new-rule.js b/lib/new-rule.js index 8f37ec6a4..1c2d5800c 100644 --- a/lib/new-rule.js +++ b/lib/new-rule.js @@ -1,19 +1,18 @@ -const fs = require('graceful-fs'); +/** + * @import {Options, ReviewOptions, RuleType} from './types/options'; + * @import {PackageElmJson} from './types/content'; + */ const path = require('node:path'); -const glob = require('glob'); const chalk = require('chalk'); +const {glob} = require('glob'); +const fs = require('graceful-fs'); const prompts = require('prompts'); +const ErrorMessage = require('./error-message'); const FS = require('./fs-wrapper'); const OsHelpers = require('./os-helpers'); -const ErrorMessage = require('./error-message'); const packageNameRegex = /.+\/(elm-)?review-.+/; -/** - * @import {Options, ReviewOptions, RuleType} from './types/options'; - * @import {PackageElmJson} from './types/content'; - */ - /** * @param {ReviewOptions} options */ diff --git a/lib/optimize-js.js b/lib/optimize-js.js index ef2457614..551b2194f 100644 --- a/lib/optimize-js.js +++ b/lib/optimize-js.js @@ -1,7 +1,5 @@ -const FS = require('./fs-wrapper'); const Benchmark = require('./benchmark'); - -module.exports = {optimize}; +const FS = require('./fs-wrapper'); async function optimize(options, elmModulePath, isReviewAppApp) { if (options.debug || !elmModulePath) { @@ -518,3 +516,7 @@ function jsonToHash(json) { } ]; } + +module.exports = { + optimize +}; diff --git a/lib/options.js b/lib/options.js index a347cc091..ce049b3a8 100644 --- a/lib/options.js +++ b/lib/options.js @@ -1,20 +1,19 @@ +/** + * @import {ParsedArgs} from 'minimist'; + * @import {Path} from './types/path'; + * @import {Flag, Multi} from './types/flag'; + * @import {Options, Subcommand, Template} from './types/options'; + */ const path = require('node:path'); const chalk = require('chalk'); -const wrap = require('wrap-ansi'); +const levenshtein = require('fastest-levenshtein'); const findUp = require('find-up'); const minimist = require('minimist'); -const levenshtein = require('fastest-levenshtein'); +const wrap = require('wrap-ansi'); const packageJson = require('../package.json'); -const Flags = require('./flags'); -const ErrorMessage = require('./error-message'); const exit = require('../vendor/exit'); - -/** - * @import {ParsedArgs} from "minimist" - * @import {Path} from "./types/path" - * @import {Flag, Multi} from "./types/flag" - * @import {Options, Subcommand, Template} from "./types/options" - */ +const ErrorMessage = require('./error-message'); +const Flags = require('./flags'); /* These contain all the options that derive what and how elm-review will behave. diff --git a/lib/os-helpers.js b/lib/os-helpers.js index 77d15f84d..53d79af01 100644 --- a/lib/os-helpers.js +++ b/lib/os-helpers.js @@ -1,6 +1,6 @@ -/** - * @import {Path} from "./types/path" - */ +// eslint-disable-next-line @typescript-eslint/ban-ts-comment -- the noUnusedLocals bug is non-deterministic. +// @ts-ignore(TS6133): There's a bug in noUnusedLocals (microsoft/TypeScript#58368). +/** @import {Path} from './types/path'; */ /** * @param {Path} path_ diff --git a/lib/parse-elm-worker.js b/lib/parse-elm-worker.js index fcfe9cd98..6cf328fce 100644 --- a/lib/parse-elm-worker.js +++ b/lib/parse-elm-worker.js @@ -1,15 +1,14 @@ // Code very much inspired by // https://blog.logrocket.com/a-complete-guide-to-threads-in-node-js-4fa3898fe74f/ -const {parentPort} = require('node:worker_threads'); -const promisifyPort = require('./promisify-port'); - /** - * @import {MessagePort} from "worker_threads" - * @import {ElmFile} from "./types/content" - * @import {ParserApp} from "./types/parse-elm" - * @import {ParseJob} from "./types/parse-elm" + * @import {MessagePort} from 'worker_threads'; + * @import {ElmFile} from './types/content'; + * @import {ParserApp} from './types/parse-elm'; + * @import {ParseJob} from './types/parse-elm'; */ +const {parentPort} = require('node:worker_threads'); +const promisifyPort = require('./promisify-port'); const appForElmModule = Object.create(null); diff --git a/lib/parse-elm.js b/lib/parse-elm.js index 5ae586945..abdaa7948 100644 --- a/lib/parse-elm.js +++ b/lib/parse-elm.js @@ -1,14 +1,13 @@ // Code very much inspired by // https://blog.logrocket.com/a-complete-guide-to-threads-in-node-js-4fa3898fe74f/ -const os = require('node:os'); -const path = require('node:path'); - /** - * @import {Source, ElmFile} from "./types/content" - * @import {ParseJob} from "./types/parse-elm" - * @import {Path} from "./types/path" + * @import {Source, ElmFile} from './types/content'; + * @import {ParseJob} from './types/parse-elm'; + * @import {Path} from './types/path'; */ +const os = require('node:os'); +const path = require('node:path'); /** * A worker and the information whether it is currently busy. @@ -30,12 +29,6 @@ const queue = []; const {Worker} = require('node:worker_threads'); -module.exports = { - parse, - prepareWorkers: prepareWorkers(Worker), - terminateWorkers -}; - /** * Prepare the workers. * @@ -143,3 +136,9 @@ function runWorker(availableWorker, queueItem) { elmParserPath: queueItem.elmParserPath }); } + +module.exports = { + parse, + prepareWorkers: prepareWorkers(Worker), + terminateWorkers +}; diff --git a/lib/path-helpers.js b/lib/path-helpers.js index 4af17e8a1..a76f00067 100644 --- a/lib/path-helpers.js +++ b/lib/path-helpers.js @@ -1,7 +1,3 @@ -module.exports = { - format -}; - /** * Format a path so that you can `cd` it. * @@ -12,3 +8,7 @@ function format(path) { const regex = /([^\w%+,./:=@-])/g; return path.replace(regex, '\\$1'); } + +module.exports = { + format +}; diff --git a/lib/project-dependencies.js b/lib/project-dependencies.js index b515d00d4..689645718 100644 --- a/lib/project-dependencies.js +++ b/lib/project-dependencies.js @@ -1,9 +1,5 @@ const ProjectJsonFiles = require('./project-json-files'); -module.exports = { - collect -}; - async function collect(options, elmJson, elmVersion) { const dependenciesEntries = elmJson.type === 'application' @@ -86,3 +82,7 @@ function defaultElmJson(name, packageVersion) { 'test-dependencies': {} }; } + +module.exports = { + collect +}; diff --git a/lib/project-json-files.js b/lib/project-json-files.js index 3725d0132..6d1291025 100644 --- a/lib/project-json-files.js +++ b/lib/project-json-files.js @@ -1,14 +1,13 @@ -const path = require('node:path'); -const os = require('node:os'); -const {default: got} = require('got'); -const FS = require('./fs-wrapper'); - /** - * @import {Path} from "./types/path" - * @import {VersionString} from "./types/version" - * @import {Options} from "./types/options" - * @import {PackageElmJson} from "./types/content" + * @import {Path} from './types/path'; + * @import {VersionString} from './types/version'; + * @import {Options} from './types/options'; + * @import {PackageElmJson} from './types/content'; */ +const os = require('node:os'); +const path = require('node:path'); +const got = require('got').default; +const FS = require('./fs-wrapper'); const elmRoot = process.env.ELM_HOME ?? diff --git a/lib/promisify-port.js b/lib/promisify-port.js index b9ad519b4..b7d6bb97e 100644 --- a/lib/promisify-port.js +++ b/lib/promisify-port.js @@ -1,9 +1,15 @@ +/** + * @import { PortsToPromise } from './types/promisify-port'; + */ + +module.exports = promisifyPort; + /** * Allows to treat a pair of ports as one promise. * It sends a message into `sendTrough` and resolves the promise with the first "response" data on `subscribeTo`. * * @template DataIn,DataOut - * @param {import("./types/promisify-port").PortsToPromise} obj + * @param {PortsToPromise} obj * @returns {PromiseLike} */ function promisifyPort({subscribeTo, sendThrough, data}) { @@ -21,5 +27,3 @@ function promisifyPort({subscribeTo, sendThrough, data}) { sendThrough.send(data); }); } - -module.exports = promisifyPort; diff --git a/lib/remote-template.js b/lib/remote-template.js index 8a70c8a8b..839ea365d 100644 --- a/lib/remote-template.js +++ b/lib/remote-template.js @@ -1,27 +1,20 @@ -const fs = require('graceful-fs'); -const path = require('node:path'); +/** + * @import {OptionsOfJSONResponseBody} from 'got'; + * @import {Options, Template} from './types/options'; + * @import {ApplicationElmJson} from './types/content'; + * @import {Path} from './types/path'; + */ const https = require('node:https'); -const {default: got} = require('got'); +const path = require('node:path'); const chalk = require('chalk'); +const fs = require('graceful-fs'); +const got = require('got').default; const Debug = require('./debug'); +const ErrorMessage = require('./error-message'); const FS = require('./fs-wrapper'); const MinVersion = require('./min-version'); -const ErrorMessage = require('./error-message'); const TemplateDependencies = require('./template-dependencies'); -/** - * @import {OptionsOfJSONResponseBody} from "got" - * @import {Options, Template} from "./types/options" - * @import {ApplicationElmJson} from "./types/content" - * @import {Path} from "./types/path" - */ - -module.exports = { - getRelevantCommit, - getRemoteElmJson, - downloadSourceDirectories -}; - // GET LATEST INFORMATION ABOUT REPOSITORY function getRelevantCommit(options, template) { @@ -307,3 +300,9 @@ async function makeGitHubApiRequest(options, url, handleNotFound) { throw error; } } + +module.exports = { + getRelevantCommit, + getRemoteElmJson, + downloadSourceDirectories +}; diff --git a/lib/report.js b/lib/report.js index 710afefaa..4ea21556d 100644 --- a/lib/report.js +++ b/lib/report.js @@ -1,15 +1,10 @@ -const Benchmark = require('./benchmark'); -const StyledMessage = require('./styled-message'); - -module.exports = { - report -}; - /** * @import { Options } from './types/options'; * @import { StyledMessage as StyledMsg } from './types/styled-message'; * @import { SuppressedErrorsFile } from './types/suppressed'; */ +const Benchmark = require('./benchmark'); +const StyledMessage = require('./styled-message'); /** * @param {Options} options @@ -89,3 +84,7 @@ function safeConsoleLog(message) { }); }); } + +module.exports = { + report +}; diff --git a/lib/result-cache-json.js b/lib/result-cache-json.js index ac084000c..7f24a4d8f 100644 --- a/lib/result-cache-json.js +++ b/lib/result-cache-json.js @@ -1,12 +1,7 @@ -module.exports = { - replacer, - reviver -}; - -/** - * @import {Replacer, Reviver} from "./types/json" - * @import {Value, ValueStruct} from "./types/elm-internals" - */ +// @ts-expect-error(TS6133): There's a bug in noUnusedLocals (microsoft/TypeScript#58368). +/** @import {Replacer, Reviver} from './types/json'; */ +// @ts-expect-error(TS6133): There's a bug in noUnusedLocals (microsoft/TypeScript#58368). +/** @import {Value, ValueStruct} from './types/elm-internals'; */ /** @type {Replacer} */ function replacer(_key, value_) { @@ -128,3 +123,8 @@ function _ListFromArrayPROD(array) { return out; } + +module.exports = { + replacer, + reviver +}; diff --git a/lib/result-cache-worker.js b/lib/result-cache-worker.js index 580b8c7dd..9efa99524 100644 --- a/lib/result-cache-worker.js +++ b/lib/result-cache-worker.js @@ -1,7 +1,6 @@ -const fs = require('graceful-fs'); - -const {parentPort} = require('node:worker_threads'); const path = require('node:path'); +const {parentPort} = require('node:worker_threads'); +const fs = require('graceful-fs'); const ResultCacheJson = require('./result-cache-json'); if (parentPort) { diff --git a/lib/result-cache.js b/lib/result-cache.js index 1cfe05872..6d9738f32 100644 --- a/lib/result-cache.js +++ b/lib/result-cache.js @@ -1,18 +1,13 @@ +/** + * @import {Options} from './types/options'; + * @import {Path} from './types/path'; + */ const path = require('node:path'); -const Debug = require('./debug'); -const FS = require('./fs-wrapper'); const AppState = require('./state'); const Benchmark = require('./benchmark'); +const Debug = require('./debug'); const ResultCacheJson = require('./result-cache-json'); - -/** - * @import {Options} from "./types/options" - * @import {Path} from "./types/path" - */ - -module.exports = { - load -}; +const FS = require('./fs-wrapper'); let worker = null; const resultCache = new Map(); @@ -135,3 +130,7 @@ async function saveToFile(options, data) { ResultCacheJson.replacer ); } + +module.exports = { + load +}; diff --git a/lib/review-dependencies.js b/lib/review-dependencies.js index 81ed81a2e..122eddce2 100644 --- a/lib/review-dependencies.js +++ b/lib/review-dependencies.js @@ -1,9 +1,5 @@ const ProjectJsonFiles = require('./project-json-files'); -module.exports = { - collectRuleLinks -}; - async function collectRuleLinks(reviewDirectDependencies, elmVersion) { const elmJsonForReviewDependenciesPromises = Object.entries( reviewDirectDependencies @@ -62,3 +58,7 @@ function linkToModule(dependencyName, packageVersion, moduleName) { const urlModuleName = moduleName.split('.').join('-'); return `https://package.elm-lang.org/packages/${dependencyName}/${packageVersion}/${urlModuleName}`; } + +module.exports = { + collectRuleLinks +}; diff --git a/lib/run-review.js b/lib/run-review.js index 1beda37e9..f0a4e53bd 100644 --- a/lib/run-review.js +++ b/lib/run-review.js @@ -1,22 +1,16 @@ +/** + * @import {Options} from './types/options'; + * @import {App} from './types/app'; + */ + const path = require('node:path'); const chalk = require('chalk'); -const Report = require('./report'); -const AppState = require('./state'); const Benchmark = require('./benchmark'); const promisifyPort = require('./promisify-port'); +const Report = require('./report'); +const AppState = require('./state'); const SuppressedErrors = require('./suppressed-errors'); -/** - * @import {Options} from "./types/options" - * @import {App} from "./types/app" - */ - -module.exports = { - runReview, - startReview, - requestReview -}; - /** * @param {Options} options * @param {App} app @@ -91,3 +85,9 @@ function requestReview(options, app) { startReview(options, app); } } + +module.exports = { + runReview, + startReview, + requestReview +}; diff --git a/lib/runner.js b/lib/runner.js index 52ed34359..66a697caf 100755 --- a/lib/runner.js +++ b/lib/runner.js @@ -1,28 +1,27 @@ #!/usr/bin/env node -const Hash = require('./hash'); -const Report = require('./report'); -const AppState = require('./state'); -const Autofix = require('./autofix'); +/** + * @import {Options} from './types/options'; + * @import {App, FileReceipt} from './types/app'; + * @import {ElmFile, Readme, ElmJsonData, Dependencies, LinksToRuleDocs, NonElmFiles, ExtraFileRequest, ApplicationElmJson} from './types/content' + * @import {SuppressedErrorsFile} from './types/suppressed'; + * @import {AppHash} from './types/build'; + * @import {FixMode} from './types/fix'; + */ +const exit = require('../vendor/exit'); const AppWrapper = require('./app-wrapper'); +const Autofix = require('./autofix'); +const {getProjectFiles} = require('./elm-files'); +const ErrorMessage = require('./error-message'); const ExtraFiles = require('./extra-files'); +const Hash = require('./hash'); const ModuleCache = require('./module-cache'); -const ErrorMessage = require('./error-message'); -const {getProjectFiles} = require('./elm-files'); -const SuppressedErrors = require('./suppressed-errors'); -const ReviewDependencies = require('./review-dependencies'); const ProjectDependencies = require('./project-dependencies'); +const Report = require('./report'); +const ReviewDependencies = require('./review-dependencies'); const {runReview, startReview, requestReview} = require('./run-review'); -const exit = require('../vendor/exit'); - -/** - * @import {Options} from "./types/options" - * @import {App, FileReceipt} from "./types/app" - * @import {ElmFile, Readme, ElmJsonData, Dependencies, LinksToRuleDocs, NonElmFiles, ExtraFileRequest, ApplicationElmJson} from './types/content' - * @import {SuppressedErrorsFile} from "./types/suppressed" - * @import {AppHash} from "./types/build" - * @import {FixMode} from "./types/fix" - */ +const AppState = require('./state'); +const SuppressedErrors = require('./suppressed-errors'); /** * Send collected information to the Elm review application. diff --git a/lib/spinner.js b/lib/spinner.js index e03562358..00c8a5de3 100644 --- a/lib/spinner.js +++ b/lib/spinner.js @@ -1,23 +1,14 @@ -const ora = require('ora'); -const AppState = require('./state'); - /** - * @import {Options} from "./types/options" - * @import {Ora} from "ora" + * @import {Options} from './types/options'; */ +const ora = require('ora'); +const AppState = require('./state'); /** @type {Options} */ const options = AppState.getOptions(); -module.exports = { - setText: options.report === 'json' ? (v) => v : setText, - succeed: options.report === 'json' ? (v) => v : succeed, - succeedAndNowDo: options.report === 'json' ? (v) => v : succeedAndNowDo, - fail: options.report === 'json' ? (v) => v : fail -}; - /** - * @type {Ora | null} + * @type {ora.Ora | null} */ let spinner; @@ -79,3 +70,18 @@ function fail(text) { spinner.fail(text); spinner = null; } + +/** + * @template {(v: string) => void} T + * @param {T} func + */ +function exportFunc(func) { + return options.report === 'json' ? () => {} : func; +} + +module.exports = { + setText: exportFunc(setText), + succeed: exportFunc(succeed), + succeedAndNowDo: exportFunc(succeedAndNowDo), + fail: exportFunc(fail) +}; diff --git a/lib/state.js b/lib/state.js index 1dbfd483f..b991ae50b 100644 --- a/lib/state.js +++ b/lib/state.js @@ -1,44 +1,21 @@ #!/usr/bin/env node /** - * @import {SubscribePort} from "./types/promisify-port" - * @import {Path} from "./types/path" - * @import {Model, Msg} from "./types/state" - * @import {FileId, FilesProposedByCurrentFix} from "./types/state" - * @import {ElmFile, Readme} from "./types/content" - * @import {Options} from "./types/options" + * @import {SubscribePort} from './types/promisify-port'; + * @import {Path} from './types/path'; + * @import {Model, Msg} from './types/state'; + * @import {FileId, FilesProposedByCurrentFix} from './types/state'; + * @import {ElmFile, Readme} from './types/content'; + * @import {Options} from './types/options'; */ - -const options_ = require('./options'); const exit = require('../vendor/exit'); +const options_ = require('./options'); /** * @type {Options} */ const options = options_.compute(process.argv); -module.exports = { - // ACCESS - getOptions, - getFileFromMemoryCache, - filesProposedByCurrentFix, - - // Messages - initializedApp, - subscribe, - exitRequested, - filesWereUpdated, - readmeChanged, - buildRestarted, - requestReview, - reviewFinished, - writingToFileSystemCacheStarted, - writingToFileSystemCacheFinished, - fixProposalReceived, - fixWasAccepted, - fixWasRefused -}; - // MODEL /** @@ -404,3 +381,25 @@ function fixWasRefused() { $: 'fixWasRefused' }); } + +module.exports = { + // ACCESS + getOptions, + getFileFromMemoryCache, + filesProposedByCurrentFix, + + // Messages + initializedApp, + subscribe, + exitRequested, + filesWereUpdated, + readmeChanged, + buildRestarted, + requestReview, + reviewFinished, + writingToFileSystemCacheStarted, + writingToFileSystemCacheFinished, + fixProposalReceived, + fixWasAccepted, + fixWasRefused +}; diff --git a/lib/styled-message.js b/lib/styled-message.js index 8fad5e9f8..2502d050b 100644 --- a/lib/styled-message.js +++ b/lib/styled-message.js @@ -1,14 +1,13 @@ -const chalk = require('chalk'); - -const wrap = require('wrap-ansi'); -const stripAnsi = require('strip-ansi'); -const terminalLink = require('terminal-link'); - /** - * @import {Options} from "./types/options" + * @import {Options} from './types/options'; * @import {FormattedString, StyledMessage} from './types/styled-message' */ +const chalk = require('chalk'); +const stripAnsi = require('strip-ansi'); +const terminalLink = require('terminal-link'); +const wrap = require('wrap-ansi'); + // LOG /** diff --git a/lib/suppressed-errors.js b/lib/suppressed-errors.js index b55e53a7b..13338fb6d 100644 --- a/lib/suppressed-errors.js +++ b/lib/suppressed-errors.js @@ -1,23 +1,16 @@ -const path = require('node:path'); +/** + * @import {Options} from './types/options'; + * @import {Path} from './types/path'; + * @import {Suppression,SuppressedErrorsFile} from './types/suppressed'; + */ const childProcess = require('node:child_process'); -const {glob} = require('glob'); +const path = require('node:path'); const chalk = require('chalk'); +const {glob} = require('glob'); +const exit = require('../vendor/exit'); +const ErrorMessage = require('./error-message'); const FS = require('./fs-wrapper'); const OsHelpers = require('./os-helpers'); -const ErrorMessage = require('./error-message'); -const exit = require('../vendor/exit'); - -/** - * @import {Options} from "./types/options" - * @import {Path} from "./types/path" - * @import {Suppression,SuppressedErrorsFile} from "./types/suppressed" - */ - -module.exports = { - read, - write, - checkForUncommittedSuppressions -}; // WRITE @@ -205,3 +198,9 @@ However, all tests have passed, so you don't need to run tests again after commi exit(1); } } + +module.exports = { + read, + write, + checkForUncommittedSuppressions +}; diff --git a/lib/sync-get-worker.js b/lib/sync-get-worker.js index dabc63694..911738b8e 100644 --- a/lib/sync-get-worker.js +++ b/lib/sync-get-worker.js @@ -1,5 +1,5 @@ -const {parentPort, workerData} = require('node:worker_threads'); const https = require('node:https'); +const {parentPort, workerData} = require('node:worker_threads'); const {sharedLock, requestPort} = workerData; const sharedLockArray = new Int32Array(sharedLock); diff --git a/lib/sync-get.js b/lib/sync-get.js index c3703afc5..855adbe5f 100644 --- a/lib/sync-get.js +++ b/lib/sync-get.js @@ -5,10 +5,6 @@ const { receiveMessageOnPort } = require('node:worker_threads'); -module.exports = { - startWorker -}; - /** * Start a worker thread and return a `syncGetWorker` * @@ -57,3 +53,7 @@ function startWorker() { return {get, shutDown}; } + +module.exports = { + startWorker +}; diff --git a/lib/template-dependencies.js b/lib/template-dependencies.js index 109f02d35..1042b0507 100644 --- a/lib/template-dependencies.js +++ b/lib/template-dependencies.js @@ -1,28 +1,20 @@ +/** + * @import {Options} from './types/options'; + * @import {VersionString} from './types/version'; + * @import {ApplicationElmJson, ApplicationDependencies, ApplicationDependencyList, PackageName, PackageDependencyList} from './types/content'; + */ const path = require('node:path'); const chalk = require('chalk'); -const MinVersion = require('./min-version'); -const ErrorMessage = require('./error-message'); const DependencyProvider = require('./dependency-provider'); +const ErrorMessage = require('./error-message'); const FS = require('./fs-wrapper'); +const MinVersion = require('./min-version'); /** @type {DependencyProvider | null} */ let dependencyProvider = null; const parseElmFolder = path.join(__dirname, '../parseElm'); -/** - * @import {Options} from "./types/options" - * @import {VersionString} from "./types/version" - * @import {ApplicationElmJson, ApplicationDependencies, ApplicationDependencyList, PackageName, PackageDependencyList} from "./types/content" - */ - -module.exports = { - addRequiredDependencies, - createNewReviewElmJson, - update, - addElmSyntax -}; - /** * Add required dependencies for the application elm.json file. * @@ -335,3 +327,10 @@ function teardownDependenciesProvider() { dependencyProvider = null; } } + +module.exports = { + addRequiredDependencies, + createNewReviewElmJson, + update, + addElmSyntax +}; diff --git a/lib/types/app.ts b/lib/types/app.ts index c664e3e40..986a53d9d 100644 --- a/lib/types/app.ts +++ b/lib/types/app.ts @@ -11,7 +11,7 @@ import type {Flags} from './flags.js'; import type {Path} from './path.js'; import type {SendPort, SubscribePort} from './promisify-port.js'; import type {FilesProposedByCurrentFix} from './state.js'; -import {StyledMessage} from './styled-message.js'; +import type {StyledMessage} from './styled-message.js'; import type {SuppressedErrorsFile} from './suppressed.js'; export type Elm = { diff --git a/lib/watch.js b/lib/watch.js index 6a3969e4c..995e347e5 100644 --- a/lib/watch.js +++ b/lib/watch.js @@ -1,23 +1,22 @@ +/** + * @import {FSWatcher} from 'fs'; + * @import {ReviewOptions} from './types/options'; + * @import {App} from './types/app'; + * @import {WatchOptions} from './types/watch'; + * @import {ApplicationElmJson, ElmJson, ExtraFileRequest, SourceDirectories} from './types/content'; + * @import {Path} from './types/path'; + */ const path = require('node:path'); // TODO(@lishaduck) [engine:node@>=19.1]: Use `fs.watch` (or `@parcel/watcher`). const chokidar = require('chokidar'); +const Anonymize = require('./anonymize'); const Debug = require('./debug'); const FS = require('./fs-wrapper'); +const OsHelpers = require('./os-helpers'); const Runner = require('./runner'); const AppState = require('./state'); -const Anonymize = require('./anonymize'); -const OsHelpers = require('./os-helpers'); const SuppressedErrors = require('./suppressed-errors'); -/** - * @import {FSWatcher} from "fs" - * @import {ReviewOptions} from "./types/options" - * @import {App} from "./types/app" - * @import {WatchOptions} from "./types/watch" - * @import {ApplicationElmJson, ElmJson, ExtraFileRequest, SourceDirectories} from "./types/content" - * @import {Path} from "./types/path" - */ - let isFlushingStdio = false; /** @type {ReturnType | undefined} */ diff --git a/new-package/elm-review-package-tests/check-examples-were-updated.js b/new-package/elm-review-package-tests/check-examples-were-updated.js index 9d3e2b534..12e0e5132 100644 --- a/new-package/elm-review-package-tests/check-examples-were-updated.js +++ b/new-package/elm-review-package-tests/check-examples-were-updated.js @@ -1,8 +1,8 @@ #!/usr/bin/env node -const Ansi = require('./helpers/ansi'); const {execSync} = require('node:child_process'); const updateExamplesFromPreview = require('../maintenance/update-examples-from-preview'); +const Ansi = require('./helpers/ansi'); const preCheckGitStatus = execSync('git status --porcelain').toString().trim(); if (preCheckGitStatus !== '') { diff --git a/new-package/elm-review-package-tests/check-previews-compile.js b/new-package/elm-review-package-tests/check-previews-compile.js index b8ae63e65..73621f648 100644 --- a/new-package/elm-review-package-tests/check-previews-compile.js +++ b/new-package/elm-review-package-tests/check-previews-compile.js @@ -1,11 +1,11 @@ #!/usr/bin/env node const path = require('node:path'); -const Ansi = require('./helpers/ansi'); const {execSync} = require('node:child_process'); -const {findPreviewConfigurations} = require('./helpers/find-configurations'); // @ts-ignore - Generated file. const packageDependencies = require('../elm.json').dependencies; +const Ansi = require('./helpers/ansi'); +const {findPreviewConfigurations} = require('./helpers/find-configurations'); const root = path.dirname(__dirname); diff --git a/new-package/elm-review-package-tests/helpers/ansi.js b/new-package/elm-review-package-tests/helpers/ansi.js index ad7e551af..fee727b7d 100644 --- a/new-package/elm-review-package-tests/helpers/ansi.js +++ b/new-package/elm-review-package-tests/helpers/ansi.js @@ -1,9 +1,3 @@ -module.exports = { - red, - green, - yellow -}; - function red(text) { return '\u001B[31m' + text + '\u001B[39m'; } @@ -15,3 +9,9 @@ function green(text) { function yellow(text) { return '\u001B[33m' + text + '\u001B[39m'; } + +module.exports = { + red, + green, + yellow +}; diff --git a/new-package/elm-review-package-tests/helpers/find-configurations.js b/new-package/elm-review-package-tests/helpers/find-configurations.js index e405564ac..4b37b2f26 100644 --- a/new-package/elm-review-package-tests/helpers/find-configurations.js +++ b/new-package/elm-review-package-tests/helpers/find-configurations.js @@ -1,15 +1,11 @@ const path = require('node:path'); -const glob = require('glob'); +const {glob} = require('glob'); const root = path .resolve(__dirname, '../../') .replace(/.:/, '') .replace(/\\/g, '/'); -module.exports = { - findPreviewConfigurations -}; - /** * @returns {string[]} */ @@ -21,3 +17,7 @@ function findPreviewConfigurations() { }) .map(path.dirname); } + +module.exports = { + findPreviewConfigurations +}; diff --git a/test/run-snapshots/elm-review-something-for-new-rule/elm-review-package-tests/check-examples-were-updated.js b/test/run-snapshots/elm-review-something-for-new-rule/elm-review-package-tests/check-examples-were-updated.js index 9d3e2b534..12e0e5132 100644 --- a/test/run-snapshots/elm-review-something-for-new-rule/elm-review-package-tests/check-examples-were-updated.js +++ b/test/run-snapshots/elm-review-something-for-new-rule/elm-review-package-tests/check-examples-were-updated.js @@ -1,8 +1,8 @@ #!/usr/bin/env node -const Ansi = require('./helpers/ansi'); const {execSync} = require('node:child_process'); const updateExamplesFromPreview = require('../maintenance/update-examples-from-preview'); +const Ansi = require('./helpers/ansi'); const preCheckGitStatus = execSync('git status --porcelain').toString().trim(); if (preCheckGitStatus !== '') { diff --git a/test/run-snapshots/elm-review-something-for-new-rule/elm-review-package-tests/check-previews-compile.js b/test/run-snapshots/elm-review-something-for-new-rule/elm-review-package-tests/check-previews-compile.js index 5f55a2c91..7ea9eddc2 100644 --- a/test/run-snapshots/elm-review-something-for-new-rule/elm-review-package-tests/check-previews-compile.js +++ b/test/run-snapshots/elm-review-something-for-new-rule/elm-review-package-tests/check-previews-compile.js @@ -1,10 +1,10 @@ #!/usr/bin/env node const path = require('node:path'); -const Ansi = require('./helpers/ansi'); const {execSync} = require('node:child_process'); -const {findPreviewConfigurations} = require('./helpers/find-configurations'); const packageDependencies = require('../elm.json').dependencies; +const Ansi = require('./helpers/ansi'); +const {findPreviewConfigurations} = require('./helpers/find-configurations'); const root = path.dirname(__dirname); diff --git a/test/run-snapshots/elm-review-something-for-new-rule/elm-review-package-tests/helpers/ansi.js b/test/run-snapshots/elm-review-something-for-new-rule/elm-review-package-tests/helpers/ansi.js index ad7e551af..fee727b7d 100644 --- a/test/run-snapshots/elm-review-something-for-new-rule/elm-review-package-tests/helpers/ansi.js +++ b/test/run-snapshots/elm-review-something-for-new-rule/elm-review-package-tests/helpers/ansi.js @@ -1,9 +1,3 @@ -module.exports = { - red, - green, - yellow -}; - function red(text) { return '\u001B[31m' + text + '\u001B[39m'; } @@ -15,3 +9,9 @@ function green(text) { function yellow(text) { return '\u001B[33m' + text + '\u001B[39m'; } + +module.exports = { + red, + green, + yellow +}; diff --git a/test/run-snapshots/elm-review-something-for-new-rule/elm-review-package-tests/helpers/find-configurations.js b/test/run-snapshots/elm-review-something-for-new-rule/elm-review-package-tests/helpers/find-configurations.js index e405564ac..4b37b2f26 100644 --- a/test/run-snapshots/elm-review-something-for-new-rule/elm-review-package-tests/helpers/find-configurations.js +++ b/test/run-snapshots/elm-review-something-for-new-rule/elm-review-package-tests/helpers/find-configurations.js @@ -1,15 +1,11 @@ const path = require('node:path'); -const glob = require('glob'); +const {glob} = require('glob'); const root = path .resolve(__dirname, '../../') .replace(/.:/, '') .replace(/\\/g, '/'); -module.exports = { - findPreviewConfigurations -}; - /** * @returns {string[]} */ @@ -21,3 +17,7 @@ function findPreviewConfigurations() { }) .map(path.dirname); } + +module.exports = { + findPreviewConfigurations +}; diff --git a/test/run-snapshots/elm-review-something/elm-review-package-tests/check-examples-were-updated.js b/test/run-snapshots/elm-review-something/elm-review-package-tests/check-examples-were-updated.js index 9d3e2b534..12e0e5132 100644 --- a/test/run-snapshots/elm-review-something/elm-review-package-tests/check-examples-were-updated.js +++ b/test/run-snapshots/elm-review-something/elm-review-package-tests/check-examples-were-updated.js @@ -1,8 +1,8 @@ #!/usr/bin/env node -const Ansi = require('./helpers/ansi'); const {execSync} = require('node:child_process'); const updateExamplesFromPreview = require('../maintenance/update-examples-from-preview'); +const Ansi = require('./helpers/ansi'); const preCheckGitStatus = execSync('git status --porcelain').toString().trim(); if (preCheckGitStatus !== '') { diff --git a/test/run-snapshots/elm-review-something/elm-review-package-tests/check-previews-compile.js b/test/run-snapshots/elm-review-something/elm-review-package-tests/check-previews-compile.js index 5f55a2c91..7ea9eddc2 100644 --- a/test/run-snapshots/elm-review-something/elm-review-package-tests/check-previews-compile.js +++ b/test/run-snapshots/elm-review-something/elm-review-package-tests/check-previews-compile.js @@ -1,10 +1,10 @@ #!/usr/bin/env node const path = require('node:path'); -const Ansi = require('./helpers/ansi'); const {execSync} = require('node:child_process'); -const {findPreviewConfigurations} = require('./helpers/find-configurations'); const packageDependencies = require('../elm.json').dependencies; +const Ansi = require('./helpers/ansi'); +const {findPreviewConfigurations} = require('./helpers/find-configurations'); const root = path.dirname(__dirname); diff --git a/test/run-snapshots/elm-review-something/elm-review-package-tests/helpers/ansi.js b/test/run-snapshots/elm-review-something/elm-review-package-tests/helpers/ansi.js index ad7e551af..fee727b7d 100644 --- a/test/run-snapshots/elm-review-something/elm-review-package-tests/helpers/ansi.js +++ b/test/run-snapshots/elm-review-something/elm-review-package-tests/helpers/ansi.js @@ -1,9 +1,3 @@ -module.exports = { - red, - green, - yellow -}; - function red(text) { return '\u001B[31m' + text + '\u001B[39m'; } @@ -15,3 +9,9 @@ function green(text) { function yellow(text) { return '\u001B[33m' + text + '\u001B[39m'; } + +module.exports = { + red, + green, + yellow +}; diff --git a/test/run-snapshots/elm-review-something/elm-review-package-tests/helpers/find-configurations.js b/test/run-snapshots/elm-review-something/elm-review-package-tests/helpers/find-configurations.js index e405564ac..4b37b2f26 100644 --- a/test/run-snapshots/elm-review-something/elm-review-package-tests/helpers/find-configurations.js +++ b/test/run-snapshots/elm-review-something/elm-review-package-tests/helpers/find-configurations.js @@ -1,15 +1,11 @@ const path = require('node:path'); -const glob = require('glob'); +const {glob} = require('glob'); const root = path .resolve(__dirname, '../../') .replace(/.:/, '') .replace(/\\/g, '/'); -module.exports = { - findPreviewConfigurations -}; - /** * @returns {string[]} */ @@ -21,3 +17,7 @@ function findPreviewConfigurations() { }) .map(path.dirname); } + +module.exports = { + findPreviewConfigurations +}; diff --git a/test/snapshotter.js b/test/snapshotter.js index 6534c926f..20214511a 100644 --- a/test/snapshotter.js +++ b/test/snapshotter.js @@ -9,4 +9,6 @@ function snapshotPath(group, name) { return `test/snapshots/${group}/${name}.txt`; } -module.exports = {snapshotPath}; +module.exports = { + snapshotPath +}; diff --git a/tsconfig.json b/tsconfig.json index 9d436ed06..9223b5167 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -21,6 +21,7 @@ "noUncheckedSideEffectImports": true, "noFallthroughCasesInSwitch": true, "noUnusedParameters": true, + "noUnusedLocals": true, "forceConsistentCasingInFileNames": true, "incremental": true, "tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json" diff --git a/tsconfig.no-implicit-any.json b/tsconfig.no-implicit-any.json index 54c98b98d..4ac7ad0c3 100644 --- a/tsconfig.no-implicit-any.json +++ b/tsconfig.no-implicit-any.json @@ -14,10 +14,7 @@ "lib/elm-communication.js", "lib/elm-files.js", "lib/extra-files.js", - "lib/sync-get.js", - "lib/sync-get-worker.js", "lib/error-message.js", - "lib/path-helpers.js", "lib/flags.js", "lib/fs-wrapper.js", "lib/hash.js", @@ -30,13 +27,18 @@ "lib/os-helpers.js", "lib/parse-elm.js", "lib/parse-elm-worker.js", + "lib/path-helpers.js", "lib/project-json-files.js", "lib/promisify-port.js", "lib/report.js", "lib/result-cache-json.js", + "lib/spinner.js", "lib/state.js", "lib/styled-message.js", "lib/suppressed-errors.js", + "lib/sync-get.js", + "lib/sync-get-worker.js", + "lib/utils.js", "test/jest-helpers/cli.js", "test/jest-helpers/types/cli.ts", "test/flags.test.js",