elm-review
Advanced tools
Comparing version 2.10.2 to 2.10.3
@@ -82,13 +82,12 @@ const fs = require('fs'); | ||
function logInit(options, directory) { | ||
const message = options.template | ||
? templateInitMessage(options, directory) | ||
: regularInitMessage(options, directory); | ||
console.log( | ||
`All done! I have created a review project at ${chalk.green( | ||
(Anonymize.path(options, directory) + '/').replace(/\/\//g, '/') | ||
)} for you.` | ||
); | ||
)} for you. | ||
if (!options.template) { | ||
console.log(` | ||
You can now define your review configuration by editing ${chalk.green( | ||
Anonymize.path(options, path.join(directory, 'src/ReviewConfig.elm')) | ||
)}. | ||
${message} | ||
@@ -102,6 +101,34 @@ I recommend you take a look at the following documents: | ||
)} | ||
`); | ||
} | ||
${options.template ? templateRecommendation : ''}` | ||
); | ||
} | ||
function regularInitMessage(options, directory) { | ||
return `You can now define your review configuration by editing ${chalk.green( | ||
Anonymize.path(options, path.join(directory, 'src/ReviewConfig.elm')) | ||
)}.`; | ||
} | ||
const orange = chalk.keyword('orange'); | ||
function templateInitMessage(options, directory) { | ||
return `You chose to use someone's review configuration which can be great to get started | ||
but don't forget to review the configuration to make sure it fits your needs, | ||
both by removing rules you disagree with and by finding new rules to aid you. | ||
You can do so by editing ${chalk.green( | ||
Anonymize.path(options, path.join(directory, 'src/ReviewConfig.elm')) | ||
)}.`; | ||
} | ||
const templateRecommendation = ` | ||
By starting out with this configuration, you may end up with too many errors to handle at once. | ||
I recommend you use a mix of the following approaches: | ||
- Enable rules one by one by commenting them out at first | ||
- Use ${orange( | ||
'elm-review suppress' | ||
)} to suppress existing errors but prevent future ones (see ${orange( | ||
'elm-review suppress --help' | ||
)}). | ||
`; | ||
async function create(options, directory, template) { | ||
@@ -108,0 +135,0 @@ const configDirectory = path.join(directory, 'src'); |
@@ -6,2 +6,8 @@ const path = require('path'); | ||
/** | ||
* @typedef { import("./types/options").Options } Options | ||
* @typedef { import("./types/path").Path } Path | ||
* @typedef { import("./types/min-version").VersionString } VersionString | ||
*/ | ||
const minimalVersion = {major: 2, minor: 13}; | ||
@@ -17,2 +23,9 @@ // prettier-ignore | ||
/** | ||
* If given an input version string smaller than the hardcoded `minimalVersion`, | ||
* it will return the minimal version. | ||
* Otherwise, the input version string is returned. | ||
* @param {VersionString} version - input version string, e.g. "1.0" | ||
* @returns {VersionString} | ||
*/ | ||
function updateToAtLeastMinimalVersion(version) { | ||
@@ -37,2 +50,9 @@ const [major, minor] = version.split('.'); | ||
/** | ||
* Throws an error if the passed elm-review version is not compatible with this runner. | ||
* @param {Options} options | ||
* @param {Path} elmJsonPath - path to an elm.json file | ||
* @param {VersionString} version - version string, e.g. "1.0" | ||
* @returns void | ||
*/ | ||
function validate(options, elmJsonPath, version) { | ||
@@ -39,0 +59,0 @@ const [major, minor] = version.split('.'); |
const fs = require('fs'); | ||
const path = require('path'); | ||
const childProcess = require('child_process'); | ||
const stream = require('stream'); | ||
const chalk = require('chalk'); | ||
@@ -143,2 +144,10 @@ const prompts = require('prompts'); | ||
class IgnoreWriteStream extends stream.Writable { | ||
isTTY = true; | ||
_write(_chunk, _encoding, callback) { | ||
callback(); | ||
} | ||
} | ||
async function createProject( | ||
@@ -175,4 +184,3 @@ options, | ||
Spinner.succeedAndNowDo('Adding elm-tooling.json'); | ||
const ignoreWriteStream = {write: () => {}}; | ||
// @ts-expect-error: False positive. The type annotation for this dependency might be incorrect. | ||
const ignoreWriteStream = new IgnoreWriteStream(); | ||
await elmToolingCli(['init'], { | ||
@@ -179,0 +187,0 @@ cwd: dir, |
@@ -5,3 +5,3 @@ const path = require('path'); | ||
const minimist = require('minimist'); | ||
const levenshtein = require('fast-levenshtein'); | ||
const levenshtein = require('fastest-levenshtein'); | ||
const packageJson = require('../package.json'); | ||
@@ -450,3 +450,3 @@ const Flags = require('./flags'); | ||
...f, | ||
distance: levenshtein.get(flag, f.name) | ||
distance: levenshtein.distance(flag, f.name) | ||
})) | ||
@@ -453,0 +453,0 @@ .sort((a, b) => { |
@@ -0,3 +1,14 @@ | ||
/** | ||
* 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<DataIn, DataOut>} obj | ||
* @returns {PromiseLike<DataOut>} | ||
*/ | ||
function promisifyPort({subscribeTo, sendThrough, data}) { | ||
return new Promise((resolve) => { | ||
/** | ||
* @param {DataOut} result | ||
* @returns void | ||
*/ | ||
const handler = (result) => { | ||
@@ -4,0 +15,0 @@ subscribeTo.unsubscribe(handler); |
@@ -17,3 +17,3 @@ const Benchmark = require('./benchmark'); | ||
} else { | ||
StyledMessage.clearAndLog(options, result.errors); | ||
StyledMessage.clearAndLog(options, result.errors, false); | ||
} | ||
@@ -20,0 +20,0 @@ |
const chalk = require('chalk'); | ||
/** | ||
* @type {(input: string, columns: number) => string } | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore: wrap-ansi includes type definitions since version 8, but it also requires node 12 | ||
const wrap = require('wrap-ansi'); | ||
@@ -6,4 +12,16 @@ const stripAnsi = require('strip-ansi'); | ||
/** | ||
* @typedef { import("./types/options").Options } Options | ||
* @typedef { import('./types/styled-message').FormattedString } FormattedString | ||
* @typedef { import("./types/styled-message").StyledMessage } StyledMessage | ||
* @typedef { import('./types/styled-message').StyledMessagePart } StyledMessagePart | ||
*/ | ||
// LOG | ||
/** | ||
* @param {Options} options | ||
* @param {StyledMessage} message | ||
* @param {boolean} clearFixLine | ||
*/ | ||
function clearAndLog(options, message, clearFixLine) { | ||
@@ -20,2 +38,6 @@ if (options.watch && !options.debug && options.report !== 'json') { | ||
/** | ||
* @param {Options} options | ||
* @param {StyledMessage} message | ||
*/ | ||
function log(options, message) { | ||
@@ -28,8 +50,16 @@ const colorEnabled = options.color !== false && options.report === null; | ||
/** | ||
* @param {boolean} colorEnabled | ||
* @param {StyledMessage} message | ||
* @returns | ||
*/ | ||
function styleMessage(colorEnabled, message) { | ||
return message | ||
.map((part) => { | ||
const rawString = typeof part === 'string' ? part : part.string; | ||
if (typeof part === 'string') { | ||
return part; | ||
} | ||
if (!colorEnabled) { | ||
return rawString; | ||
return part.string; | ||
} | ||
@@ -39,4 +69,4 @@ | ||
part.href && terminalLink.isSupported | ||
? terminalLink(rawString, part.href) | ||
: rawString; | ||
? terminalLink(part.string, part.href) | ||
: part.string; | ||
@@ -48,2 +78,6 @@ return withStyling(part)(stringWithLink); | ||
/** | ||
* @param {FormattedString} part | ||
* @returns {chalk.Chalk} | ||
*/ | ||
function withStyling(part) { | ||
@@ -57,2 +91,6 @@ return part.color ? chalk.hex(part.color) : chalk; | ||
/** | ||
* @param {string} message | ||
* @returns {string} | ||
*/ | ||
function wrapLinesForTerminal(message) { | ||
@@ -59,0 +97,0 @@ return message |
@@ -202,3 +202,2 @@ /* | ||
if (elmJsonPromise === undefined) { | ||
// @ts-expect-error: False positive. The type annotation for this dependency might be incorrect. | ||
elmJsonPromise = getExecutable({ | ||
@@ -205,0 +204,0 @@ name: 'elm-json', |
{ | ||
"name": "elm-review", | ||
"version": "2.10.2", | ||
"version": "2.10.3", | ||
"description": "Run elm-review from Node.js", | ||
@@ -82,4 +82,4 @@ "engines": { | ||
"cross-spawn": "^7.0.3", | ||
"elm-tooling": "^1.6.0", | ||
"fast-levenshtein": "^3.0.0", | ||
"elm-tooling": "^1.14.1", | ||
"fastest-levenshtein": "^1.0.16", | ||
"find-up": "^4.1.0", | ||
@@ -103,3 +103,2 @@ "folder-hash": "^3.3.0", | ||
"@types/chalk": "^2.2.0", | ||
"@types/fast-levenshtein": "^0.0.2", | ||
"@types/jest": "^29.5.1", | ||
@@ -106,0 +105,0 @@ "@types/minimist": "^1.2.2", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
422528
17
7256
+ Addedfastest-levenshtein@^1.0.16
- Removedfast-levenshtein@^3.0.0
- Removedfast-levenshtein@3.0.0(transitive)
Updatedelm-tooling@^1.14.1