Skip to content

Commit

Permalink
Update dev-dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Nov 29, 2021
1 parent 411f616 commit 96e8c4f
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 64 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
"typescript": "~4.4.0",
"unist-builder": "^3.0.0",
"unist-util-remove-position": "^4.0.0",
"xo": "^0.46.0"
"xo": "^0.47.0"
},
"scripts": {
"build-packages": "node script/build-presets && node script/build-rules",
Expand All @@ -158,6 +158,8 @@
"xo": {
"prettier": true,
"rules": {
"capitalized-comments": "off",
"unicorn/prefer-code-point": "off",
"unicorn/prefer-switch": "off"
},
"overrides": [
Expand Down
2 changes: 1 addition & 1 deletion packages/unified-lint-rule/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ export type Rule<Tree extends Node = Node, Settings = unknown> = (
settings: Settings
) => Promise<Tree | undefined | void> | Tree | undefined | void

export type {Severity, Label}
export {Severity, Label} from './lib/index.js'
7 changes: 5 additions & 2 deletions script/util/presets.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@ import url from 'node:url'
* @returns {Promise<Array<{name: string, packages: Record<string, unknown>}>>}
*/
export async function presets(base) {
const files = (await fs.readdir(base)).filter((basename) =>
const allFiles = await fs.readdir(base)
const files = allFiles.filter((basename) =>
/remark-preset-lint/.test(basename)
)

return Promise.all(
files.map(async (name) => {
const href = url.pathToFileURL(path.join(base, name, 'index.js')).href
// type-coverage:ignore-next-line
const presetMod = await import(href)
/** @type {Preset} */
// type-coverage:ignore-next-line
const preset = (await import(href)).default
const preset = presetMod.default
const plugins = preset.plugins || []
/** @type {Record<string, unknown>} */
const packages = {}
Expand Down
120 changes: 60 additions & 60 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,56 +36,48 @@ test('core', async (t) => {
'# Another main heading.'
].join('\n')

let file = await remark()
.use(noHeadingPunctuation)
.use(noMultipleToplevelHeadings)
.use(lint)
.process(toVFile({path: 'virtual.md', value: doc}))

t.deepEqual(
asStrings(
(
await remark()
.use(noHeadingPunctuation)
.use(noMultipleToplevelHeadings)
.use(lint)
.process(toVFile({path: 'virtual.md', value: doc}))
).messages
),
asStrings(file.messages),
[
'virtual.md:3:1-3:24: Don’t add a trailing `.` to headings',
'virtual.md:3:1-3:24: Don’t use multiple top level headings (1:1)'
],
'should support `remark-lint` last'
)

file = await remark()
.use(lint)
.use(noHeadingPunctuation)
.use(noMultipleToplevelHeadings)
.process(toVFile({path: 'virtual.md', value: doc}))

t.deepEqual(
asStrings(
(
await remark()
.use(lint)
.use(noHeadingPunctuation)
.use(noMultipleToplevelHeadings)
.process(toVFile({path: 'virtual.md', value: doc}))
).messages
),
asStrings(file.messages),
[
'virtual.md:3:1-3:24: Don’t add a trailing `.` to headings',
'virtual.md:3:1-3:24: Don’t use multiple top level headings (1:1)'
],
'should support `remark-lint` first'
)

t.deepEqual(
asStrings((await remark().use(lint).process('.')).messages),
[],
'should support no rules'
)
file = await remark().use(lint).process('.')

t.deepEqual(
asStrings((await remark().use(finalNewline).process('')).messages),
[],
'should support successful rules'
)
t.deepEqual(asStrings(file.messages), [], 'should support no rules')

file = await remark().use(finalNewline).process('')

t.deepEqual(asStrings(file.messages), [], 'should support successful rules')

file = await remark().use(finalNewline, [2]).process('.')

t.deepEqual(
(await remark().use(finalNewline, [2]).process('.')).messages.map((d) =>
JSON.parse(JSON.stringify(d))
),
file.messages.map((d) => JSON.parse(JSON.stringify(d))),
[
{
name: '1:1',
Expand All @@ -106,36 +98,42 @@ test('core', async (t) => {
'should support a list with a severity'
)

file = await remark().use(finalNewline, true).process('.')

t.deepEqual(
asStrings((await remark().use(finalNewline, true).process('.')).messages),
asStrings(file.messages),
['1:1: Missing newline character at end of file'],
'should support a boolean (`true`)'
)

file = await remark().use(finalNewline, false).process('.')

t.deepEqual(
asStrings((await remark().use(finalNewline, false).process('.')).messages),
asStrings(file.messages),
[],
'should support a boolean (`false`)'
)

file = await remark().use(finalNewline, [true]).process('.')

t.deepEqual(
asStrings((await remark().use(finalNewline, [true]).process('.')).messages),
asStrings(file.messages),
['1:1: Missing newline character at end of file'],
'should support a list with a boolean severity (true, for on)'
)

file = await remark().use(finalNewline, [false]).process('.')

t.deepEqual(
asStrings(
(await remark().use(finalNewline, [false]).process('.')).messages
),
asStrings(file.messages),
[],
'should support a list with boolean severity (false, for off)'
)

file = await remark().use(finalNewline, ['error']).process('.')

t.deepEqual(
(await remark().use(finalNewline, ['error']).process('.')).messages.map(
(d) => JSON.parse(JSON.stringify(d))
),
file.messages.map((d) => JSON.parse(JSON.stringify(d))),
[
{
name: '1:1',
Expand All @@ -156,10 +154,10 @@ test('core', async (t) => {
'should support a list with string severity (`error`)'
)

file = await remark().use(finalNewline, ['on']).process('.')

t.deepEqual(
(await remark().use(finalNewline, ['on']).process('.')).messages.map((d) =>
JSON.parse(JSON.stringify(d))
),
file.messages.map((d) => JSON.parse(JSON.stringify(d))),
[
{
name: '1:1',
Expand All @@ -180,10 +178,10 @@ test('core', async (t) => {
'should support a list with string severity (`on`)'
)

file = await remark().use(finalNewline, ['warn']).process('.')

t.deepEqual(
(await remark().use(finalNewline, ['warn']).process('.')).messages.map(
(d) => JSON.parse(JSON.stringify(d))
),
file.messages.map((d) => JSON.parse(JSON.stringify(d))),
[
{
name: '1:1',
Expand All @@ -204,10 +202,10 @@ test('core', async (t) => {
'should support a list with string severity (`warn`)'
)

file = await remark().use(finalNewline, ['off']).process('.')

t.deepEqual(
asStrings(
(await remark().use(finalNewline, ['off']).process('.')).messages
),
asStrings(file.messages),
[],
'should support a list with string severity (`off`)'
)
Expand All @@ -228,17 +226,17 @@ test('core', async (t) => {
'should fail on incorrect severities (too low)'
)

file = await remark()
.use(
lintRule('test:rule', (tree, file) => {
file.message('Test message')
}),
['warn']
)
.process('.')

t.deepEqual(
(
await remark()
.use(
lintRule('test:rule', (tree, file) => {
file.message('Test message')
}),
['warn']
)
.process('.')
).messages.map((d) => JSON.parse(JSON.stringify(d))),
file.messages.map((d) => JSON.parse(JSON.stringify(d))),
[
{
name: '1:1',
Expand Down Expand Up @@ -270,9 +268,11 @@ test('rules', async (t) => {
const info = rule(base)
const href = url.pathToFileURL(base).href + '/index.js'

// type-coverage:ignore-next-line
const pluginMod = await import(href)
/** @type {Plugin} */
// type-coverage:ignore-next-line
const fn = (await import(href)).default
const fn = pluginMod.default

if (Object.keys(info.tests).length === 0) {
t.pass(info.ruleId + ': no tests')
Expand Down

0 comments on commit 96e8c4f

Please sign in to comment.