Skip to content

Commit 40ac4a1

Browse files
committed
Add syntax highlighting to filterResults and groupFunction help examples.
1 parent 16fe009 commit 40ac4a1

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ Only available in .ncurc.js or when importing npm-check-updates as a module.
341341
@param {SemVer} upgradedVersionSemver Upgraded version in semantic versioning format.
342342
@returns {boolean} Return true if the upgrade should be kept, otherwise it will be ignored.
343343
*/
344-
filterResults: (packageName, {currentVersion, currentVersionSemver, upgradedVersion, upgradedVersionSemver}) {
344+
filterResults: (packageName, { currentVersion, currentVersionSemver, upgradedVersion, upgradedVersionSemver }) => {
345345
const currentMajorVersion = currentVersionSemver?.[0]?.major
346346
const upgradedMajorVersion = upgradedVersionSemver?.major
347347
if (currentMajorVersion && upgradedMajorVersion) {
@@ -384,7 +384,7 @@ Only available in .ncurc.js or when importing npm-check-updates as a module.
384384
@param upgradedVersion The upgraded version number returned by the registry.
385385
@returns A predefined group name ('major' | 'minor' | 'patch' | 'majorVersionZero' | 'none') or a custom string to create your own group.
386386
*/
387-
groupFunction: (name, defaultGroup, currentSpec, upgradedSpec, upgradedVersion} {
387+
groupFunction: (name, defaultGroup, currentSpec, upgradedSpec, upgradedVersion) => {
388388
if (name === 'typescript' && defaultGroup === 'minor') {
389389
return 'major'
390390
}

src/cli-options.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,15 @@ ${codeBlock(
139139
*/`)}
140140
${chalk.cyan(
141141
'filterResults',
142-
)}: (packageName, {currentVersion, currentVersionSemver, upgradedVersion, upgradedVersionSemver}) {
143-
const currentMajorVersion = currentVersionSemver?.[0]?.major
142+
)}: (packageName, { currentVersion, currentVersionSemver, upgradedVersion, upgradedVersionSemver }) ${chalk.cyan(
143+
'=>',
144+
)} {
145+
const currentMajorVersion = currentVersionSemver?.[${chalk.blue('0')}]?.major
144146
const upgradedMajorVersion = upgradedVersionSemver?.major
145-
if (currentMajorVersion && upgradedMajorVersion) {
146-
return currentMajorVersion < upgradedMajorVersion
147+
${chalk.red('if')} (currentMajorVersion ${chalk.red('&&')} upgradedMajorVersion) {
148+
${chalk.red('return')} currentMajorVersion ${chalk.red('<')} upgradedMajorVersion
147149
}
148-
return true
150+
${chalk.red('return')} ${chalk.blue('true')}
149151
}`,
150152
{ markdown },
151153
)}
@@ -190,14 +192,16 @@ ${codeBlock(
190192
@param upgradedVersion The upgraded version number returned by the registry.
191193
@returns A predefined group name ('major' | 'minor' | 'patch' | 'majorVersionZero' | 'none') or a custom string to create your own group.
192194
*/`)}
193-
${chalk.cyan('groupFunction')}: (name, defaultGroup, currentSpec, upgradedSpec, upgradedVersion} {
194-
if (name === 'typescript' && defaultGroup === 'minor') {
195-
return 'major'
195+
${chalk.cyan('groupFunction')}: (name, defaultGroup, currentSpec, upgradedSpec, upgradedVersion) ${chalk.cyan('=>')} {
196+
${chalk.red('if')} (name ${chalk.red('===')} ${chalk.yellow(`'typescript'`)} && defaultGroup ${chalk.red(
197+
'===',
198+
)} ${chalk.yellow(`'minor'`)}) {
199+
${chalk.red('return')} ${chalk.yellow(`'major'`)}
196200
}
197-
if (name.startsWith('@myorg/')) {
198-
return 'My Org'
201+
${chalk.red('if')} (name.startsWith('@myorg/')) {
202+
${chalk.red('return')} ${chalk.yellow(`'My Org'`)}
199203
}
200-
return defaultGroup
204+
${chalk.red('return')} defaultGroup
201205
}`,
202206
{ markdown },
203207
)}
@@ -243,7 +247,9 @@ ${codeBlock(
243247
${chalk.cyan(
244248
'target',
245249
)}: (dependencyName, [{ semver, version, operator, major, minor, patch, release, build }]) ${chalk.cyan('=>')} {
246-
${chalk.red('if')} (major ${chalk.red('===')} ${chalk.blue("'0'")}) ${chalk.red('return')} ${chalk.yellow("'minor'")}
250+
${chalk.red('if')} (major ${chalk.red('===')} ${chalk.yellow("'0'")}) ${chalk.red('return')} ${chalk.yellow(
251+
"'minor'",
252+
)}
247253
${chalk.red('return')} ${chalk.yellow("'latest'")}
248254
}`,
249255
{ markdown },

0 commit comments

Comments
 (0)