Skip to content

Commit

Permalink
Rename printMessage to formatMessage
Browse files Browse the repository at this point in the history
close #43
  • Loading branch information
bluwy committed Jul 25, 2023
1 parent e391bf1 commit d282c66
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions pkg/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ console.log(messages)
Extra utilities are exported under `publint/utils`:

```js
import { printMessage } from 'publint/utils'
import { formatMessage } from 'publint/utils'
import fs from 'node:fs/promises'

const pkg = JSON.parse(
Expand All @@ -84,7 +84,7 @@ const pkg = JSON.parse(
for (const message of messages) {
// Prints default message in Node.js. Always a no-op in browsers.
// Useful for re-implementing the CLI in a programmatic way.
printMessage(message, pkg)
console.log(formatMessage(message, pkg))
}
```

Expand Down
8 changes: 4 additions & 4 deletions pkg/lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { createRequire } from 'node:module'
import sade from 'sade'
import c from 'picocolors'
import { publint } from './node.js'
import { printMessage } from '../src/message.js'
import { formatMessage } from '../src/message.js'
import { createPromiseQueue } from '../src/utils.js'

const version = createRequire(import.meta.url)('../package.json').version
Expand Down Expand Up @@ -126,23 +126,23 @@ async function lintDir(pkgDir, level, strict, compact = false) {
if (suggestions.length) {
logs.push(c.bold(c.blue('Suggestions:')))
suggestions.forEach((m, i) =>
logs.push(c.dim(`${i + 1}. `) + printMessage(m, rootPkg))
logs.push(c.dim(`${i + 1}. `) + formatMessage(m, rootPkg))
)
}

const warnings = messages.filter((v) => v.type === 'warning')
if (warnings.length) {
logs.push(c.bold(c.yellow('Warnings:')))
warnings.forEach((m, i) =>
logs.push(c.dim(`${i + 1}. `) + printMessage(m, rootPkg))
logs.push(c.dim(`${i + 1}. `) + formatMessage(m, rootPkg))
)
}

const errors = messages.filter((v) => v.type === 'error')
if (errors.length) {
logs.push(c.bold(c.red('Errors:')))
errors.forEach((m, i) =>
logs.push(c.dim(`${i + 1}. `) + printMessage(m, rootPkg))
logs.push(c.dim(`${i + 1}. `) + formatMessage(m, rootPkg))
)
process.exitCode = 1
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/lib/utils-node.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { formatMessagePath, getPkgPathValue } from '../src/utils.js'
export { printMessage } from '../src/message.js'
export { formatMessage } from '../src/message.js'
4 changes: 2 additions & 2 deletions pkg/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ export { formatMessagePath, getPkgPathValue } from '../src/utils.js'

/**
* no-op. leave users to implement themselves.
* @type {import('../utils.d.ts').printMessage}
* @type {import('../utils.d.ts').formatMessage}
*/
export function printMessage() {
export function formatMessage() {
return
}
2 changes: 1 addition & 1 deletion pkg/src/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { formatMessagePath as fp, getPkgPathValue } from './utils.js'
* @param {import('../index.d.ts').Message} m
* @param {import('./utils.js').Pkg} pkg
*/
export function printMessage(m, pkg) {
export function formatMessage(m, pkg) {
/** @param {string[]} path */
const pv = (path) => getPkgPathValue(pkg, path)

Expand Down
4 changes: 2 additions & 2 deletions pkg/tests/playground.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from 'node:path'
import { test } from 'uvu'
import { equal } from 'uvu/assert'
import { publint } from '../lib/node.js'
import { printMessage } from '../lib/utils-node.js'
import { formatMessage } from '../lib/utils-node.js'

testFixture('exports-styles', [
'EXPORTS_VALUE_INVALID',
Expand Down Expand Up @@ -131,7 +131,7 @@ function testFixture(name, expectCodes, options) {
)
console.log()
console.log('Logs:', name)
messages.forEach((m) => console.log(printMessage(m, pkg)))
messages.forEach((m) => console.log(formatMessage(m, pkg)))
console.log()
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ type Pkg = Record<string, any>

export declare function formatMessagePath(path: string[]): string
export declare function getPkgPathValue(pkg: Pkg, path: string[]): any
export declare function printMessage(msg: Message, pkg: Pkg): string | undefined
export declare function formatMessage(msg: Message, pkg: Pkg): string | undefined
4 changes: 2 additions & 2 deletions site/src/components/PkgNode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { getContext, setContext } from 'svelte'
import { messageTypeToColor } from '../utils/colors'
import { isArrayEqual } from '../utils/common'
import { printMessage } from '../utils/message'
import { formatMessage } from '../utils/message'
/** @type {string | number} */
export let key = ''
Expand Down Expand Up @@ -77,7 +77,7 @@
<div class="-mx-4">
{#each shownMessages as msg}
<div class="{messageTypeToColor(msg.type)} border-4 px-4 py-2">
{@html printMessage(msg, pkg)}
{@html formatMessage(msg, pkg)}
</div>
{/each}
{#if shownMessages.length < matchedMessages.length && !showAllMessages}
Expand Down
2 changes: 1 addition & 1 deletion site/src/utils/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { formatMessagePath as fp, getPkgPathValue } from 'publint/utils'
* @param {import('publint').Message} m
* @param {Record<string, any>} pkg
*/
export function printMessage(m, pkg) {
export function formatMessage(m, pkg) {
let str = messageToString(m, pkg)
if (str) {
str += ` (<a href="/rules.html#${m.code.toLowerCase()}">More info</a>)`
Expand Down

0 comments on commit d282c66

Please sign in to comment.