Skip to content

Commit

Permalink
Breaking: bump remark and plugins
Browse files Browse the repository at this point in the history
Changes a few escape sequences:

- `<` and `>` are no longer escaped as HTML entities
- Underscores if not used for emphasis, are escaped with a backslash
- Ampersands in URLs are escaped with a backslash.
- Square brackets if not used for definitions (links) are escaped.

Added one new rule that is a breaking change: thematic breaks must
be `---` rather than `***` or `* * *` or `- - -`.

Ref #80
  • Loading branch information
vweevers committed Nov 14, 2021
1 parent 175055a commit ecea8e2
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 31 deletions.
9 changes: 4 additions & 5 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
version: 2
updates:
# Disabled until we migrate to remark 13
# - package-ecosystem: npm
# directory: /
# schedule:
# interval: monthly
- package-ecosystem: npm
directory: /
schedule:
interval: monthly
- package-ecosystem: github-actions
directory: /
schedule:
Expand Down
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,15 @@ README.md:5:3

## Rules

- [Insert links to GitHub issues, PRs and usernames](https://www.npmjs.com/package/remark-github) (not linted yet)
- [Use `-` as marker for bullets of items in unordered lists](https://www.npmjs.com/package/remark-lint-unordered-list-marker-style) (`- item`)
- [Use `_` as marker for emphasis](https://www.npmjs.com/package/remark-lint-emphasis-marker) (`_emphasis_`)
- [Use `*` as marker for strong](https://www.npmjs.com/package/remark-lint-strong-marker) (`**strong**`)
- [Use `x` as marker for checkboxes](https://www.npmjs.com/package/remark-lint-checkbox-character-style) (`- [x] item`)
- [Use backtick as marker for fenced code block](https://www.npmjs.com/package/remark-lint-fenced-code-marker)
- [Always use fences for code blocks](https://www.npmjs.com/package/remark-lint-code-block-style)
- [Use `---` for thematic breaks](https://www.npmjs.com/package/remark-lint-rule-style)
- [Insert links to GitHub issues, PRs and usernames](https://www.npmjs.com/package/remark-github) (not linted)
- [Collapse a Table of Contents if it exists](https://www.npmjs.com/package/remark-collapse) (not linted)
- [Fenced code blocks](https://www.npmjs.com/package/remark-lint-code-block-style)
- [End file with newline](https://www.npmjs.com/package/remark-lint-final-newline)
- No dead links, references and definitions:
- [No dead internal links](https://www.npmjs.com/package/remark-validate-links)
Expand All @@ -131,9 +137,9 @@ README.md:5:3
- [No literal URLs without angle-brackets](https://www.npmjs.com/package/remark-lint-no-literal-urls)
- [No angle-bracketed links (`<url>`) without protocol](https://www.npmjs.com/package/remark-lint-no-auto-link-without-protocol)
- [No blank lines without markers (`>`) in a blockquote](https://www.npmjs.com/package/remark-lint-no-blockquote-without-marker)
- [Table cells must be padded](https://www.npmjs.com/package/remark-lint-table-cell-padding) ([#16](https://github.com/vweevers/hallmark/issues/16))
- [Table rows must be fenced with pipes](https://www.npmjs.com/package/remark-lint-table-pipes)
- [Checkboxes must use `x` as marker](https://www.npmjs.com/package/remark-lint-checkbox-character-style)
- Tables:
- [Table cells must be padded](https://www.npmjs.com/package/remark-lint-table-cell-padding) ([#16](https://github.com/vweevers/hallmark/issues/16))
- [Table rows must be fenced with pipes](https://www.npmjs.com/package/remark-lint-table-pipes)

## Usage

Expand Down
30 changes: 24 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { engine } from 'unified-engine'
import supportsColor from 'supports-color'
import { fromCallback } from 'catering'
import defaultReporter from 'vfile-reporter-shiny'
import processor from 'remark'
import { remark as processor } from 'remark'
import remarkGfm from 'remark-gfm'
import remarkCommonChangelog from 'remark-common-changelog'
import remarkGithub from 'remark-github'
import remarkAutolinkReferences from 'remark-autolink-references'
Expand Down Expand Up @@ -78,6 +79,15 @@ function hallmark (options, callback) {
reporter,
reporterOptions,
plugins: [
[remarkGfm, {
tableCellPadding: true,

// Allow disabling padding because on big tables it creates noise.
tablePipeAlign: paddedTable,

// In addition, use fixed width columns. TODO: use string-width package
stringLength: paddedTable ? (s) => String(s).length : () => 3
}],
[remarkCommonChangelog, { cwd, fix, pkg, repository, ...changelog }],
[remarkGithub, { repository }],

Expand All @@ -100,13 +110,21 @@ function hallmark (options, callback) {
settings: {
// One style for code blocks, whether they have a language or not.
fences: true,
listItemIndent: '1',

// Allow disabling padding because on big tables it creates noise.
tablePipeAlign: paddedTable,
// Whether to indent the content of list items with the size of the bullet plus one space
listItemIndent: 'one',

// Marker to use for bullets of items in unordered lists
bullet: '-',

// Marker to use for thematic breaks
rule: '-',

// Marker to use to serialize emphasis
emphasis: '_',

// In addition, use fixed width columns.
stringLength: paddedTable ? (s) => String(s).length : () => 3
// Marker to use to serialize strong
strong: '*'
},
pluginPrefix: 'remark',
// "Whether to write successfully processed files"
Expand Down
10 changes: 10 additions & 0 deletions lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ import remarkLintTablePipes from 'remark-lint-table-pipes'
import remarkLintCheckboxCharacterStyle from 'remark-lint-checkbox-character-style'
import remarkLintDefinitionCase from 'remark-lint-definition-case'
import remarkValidateLinks from 'remark-validate-links'
import remarkLintEmphasisMarker from 'remark-lint-emphasis-marker'
import remarkLintStrongMarker from 'remark-lint-strong-marker'
import remarkLintUnorderedListMarkerStyle from 'remark-lint-unordered-list-marker-style'
import remarkLintFencedCodeMarker from 'remark-lint-fenced-code-marker'
import remarkLintRuleStyle from 'remark-lint-rule-style'

export default function ({ fix, repository, paddedTable, validateLinks }) {
const preset = {
Expand All @@ -41,9 +46,14 @@ export default function ({ fix, repository, paddedTable, validateLinks }) {

if (!fix) {
preset.plugins.push(
[remarkLintEmphasisMarker, '_'],
[remarkLintStrongMarker, '*'],
remarkLintFinalNewline,
[remarkLintUnorderedListMarkerStyle, '-'],
remarkLintListItemBulletIndent,
[remarkLintListItemIndent, 'space'],
[remarkLintFencedCodeMarker, '`'],
[remarkLintRuleStyle, '---'],
remarkLintNoAutoLinkWithoutProtocol,
remarkLintNoBlockquoteWithoutMarker,
remarkLintNoLiteralUrls,
Expand Down
32 changes: 19 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,37 @@
"deglob": "^4.0.0",
"find-file-up": "^2.0.1",
"find-githost": "^1.0.0",
"remark": "^12.0.1",
"remark-autolink-references": "^1.0.0",
"remark": "^14.0.1",
"remark-autolink-references": "^2.0.0",
"remark-collapse": "~0.1.2",
"remark-common-changelog": "^0.0.3",
"remark-github": "^9.0.1",
"remark-lint": "^7.0.1",
"remark-gfm": "^3.0.1",
"remark-github": "^11.2.1",
"remark-lint": "^9.1.0",
"remark-lint-blockquote-indentation": "^3.1.0",
"remark-lint-checkbox-character-style": "^2.0.1",
"remark-lint-checkbox-content-indent": "^2.0.1",
"remark-lint-checkbox-character-style": "^4.1.0",
"remark-lint-checkbox-content-indent": "^4.1.0",
"remark-lint-code-block-style": "^3.1.0",
"remark-lint-definition-case": "^3.1.0",
"remark-lint-emphasis-marker": "^3.1.0",
"remark-lint-fenced-code-marker": "^3.1.0",
"remark-lint-final-newline": "^2.1.0",
"remark-lint-hard-break-spaces": "^3.1.0",
"remark-lint-list-item-bullet-indent": "^2.0.1",
"remark-lint-list-item-bullet-indent": "^4.1.0",
"remark-lint-list-item-indent": "^3.1.0",
"remark-lint-no-auto-link-without-protocol": "^3.1.0",
"remark-lint-no-blockquote-without-marker": "^3.0.1",
"remark-lint-no-blockquote-without-marker": "^5.1.0",
"remark-lint-no-duplicate-definitions": "^3.1.0",
"remark-lint-no-heading-content-indent": "^2.0.1",
"remark-lint-no-inline-padding": "^2.0.1",
"remark-lint-no-heading-content-indent": "^4.1.0",
"remark-lint-no-inline-padding": "^4.1.0",
"remark-lint-no-literal-urls": "^3.1.0",
"remark-lint-no-undefined-references": "^2.0.1",
"remark-lint-no-undefined-references": "^4.1.0",
"remark-lint-no-unused-definitions": "^3.1.0",
"remark-lint-table-cell-padding": "^2.0.1",
"remark-lint-table-pipes": "^2.0.1",
"remark-lint-rule-style": "^3.1.0",
"remark-lint-strong-marker": "^3.1.0",
"remark-lint-table-cell-padding": "^4.1.1",
"remark-lint-table-pipes": "^4.1.0",
"remark-lint-unordered-list-marker-style": "^3.1.0",
"remark-toc": "^8.0.1",
"remark-validate-links": "^11.0.2",
"subarg": "^1.0.0",
Expand Down
7 changes: 6 additions & 1 deletion test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ test('lints various', function (t) {
t.ifError(err)
t.is(actual, expected)
t.same(file.messages.map(String), [
'test.md:3:1-3:10: Marker style should be `-`',
'test.md:4:1-4:8: Marker style should be `-`',
'test.md:5:1-5:6: Marker style should be `-`',
'test.md:5:3-5:6: Found reference to undefined definition',
'test.md:6:1-6:21: Marker style should be `-`',
'test.md:6:3-6:21: Don’t use literal URLs without angle brackets',
'test.md:12:23: Cell should be padded',
'test.md:16:1-16:9: Code blocks should be fenced',
'test.md:28:4-28:5: Checked checkboxes should use `x` as a marker'
'test.md:28:5: Checked checkboxes should use `x` as a marker',
'test.md:32:1-32:6: Rules should use `---`'
])
t.end()
})
Expand Down
2 changes: 2 additions & 0 deletions test/fixture/00-various-input.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ yes()
- [X] no
- [x] yes
- [ ] foo

* * *
4 changes: 3 additions & 1 deletion test/fixture/00-various-output.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

- a [**@user**](https://github.com/user)
- b [#12](https://github.com/test/test/issues/12)
- [c]
- \[c]
- <http://example.com>

## table
Expand Down Expand Up @@ -30,3 +30,5 @@ yes()
- [x] no
- [x] yes
- [ ] foo

---

0 comments on commit ecea8e2

Please sign in to comment.