Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

remark-lint-emphasis-marker

Package Overview
Dependencies
Maintainers
2
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remark-lint-emphasis-marker - npm Package Compare versions

Comparing version 2.0.1 to 3.0.0

index.d.ts

95

index.js

@@ -25,27 +25,34 @@ /**

*
* @example {"setting": "*", "name": "ok.md"}
* @example
* {"setting": "*", "name": "ok.md"}
*
* *foo*
*
* @example {"setting": "*", "name": "not-ok.md", "label": "input"}
* @example
* {"setting": "*", "name": "not-ok.md", "label": "input"}
*
* _foo_
*
* @example {"setting": "*", "name": "not-ok.md", "label": "output"}
* @example
* {"setting": "*", "name": "not-ok.md", "label": "output"}
*
* 1:1-1:6: Emphasis should use `*` as a marker
*
* @example {"setting": "_", "name": "ok.md"}
* @example
* {"setting": "_", "name": "ok.md"}
*
* _foo_
*
* @example {"setting": "_", "name": "not-ok.md", "label": "input"}
* @example
* {"setting": "_", "name": "not-ok.md", "label": "input"}
*
* *foo*
*
* @example {"setting": "_", "name": "not-ok.md", "label": "output"}
* @example
* {"setting": "_", "name": "not-ok.md", "label": "output"}
*
* 1:1-1:6: Emphasis should use `_` as a marker
*
* @example {"name": "not-ok.md", "label": "input"}
* @example
* {"name": "not-ok.md", "label": "input"}
*

@@ -55,7 +62,9 @@ * *foo*

*
* @example {"name": "not-ok.md", "label": "output"}
* @example
* {"name": "not-ok.md", "label": "output"}
*
* 2:1-2:6: Emphasis should use `*` as a marker
*
* @example {"setting": "💩", "name": "not-ok.md", "label": "output", "config": {"positionless": true}}
* @example
* {"setting": "💩", "name": "not-ok.md", "label": "output", "positionless": true}
*

@@ -65,46 +74,42 @@ * 1:1: Incorrect emphasis marker `💩`: use either `'consistent'`, `'*'`, or `'_'`

'use strict'
/**
* @typedef {import('mdast').Root} Root
* @typedef {'*'|'_'} Marker
* @typedef {'consistent'|Marker} Options
*/
var rule = require('unified-lint-rule')
var visit = require('unist-util-visit')
var position = require('unist-util-position')
var generated = require('unist-util-generated')
import {lintRule} from 'unified-lint-rule'
import {visit} from 'unist-util-visit'
import {pointStart} from 'unist-util-position'
module.exports = rule('remark-lint:emphasis-marker', emphasisMarker)
const remarkLintEmphasisMarker = lintRule(
'remark-lint:emphasis-marker',
/** @type {import('unified-lint-rule').Rule<Root, Options>} */
(tree, file, option = 'consistent') => {
const value = String(file)
var markers = {null: true, '*': true, _: true}
if (option !== '*' && option !== '_' && option !== 'consistent') {
file.fail(
'Incorrect emphasis marker `' +
option +
"`: use either `'consistent'`, `'*'`, or `'_'`"
)
}
function emphasisMarker(tree, file, option) {
var contents = String(file)
var preferred =
typeof option === 'string' && option !== 'consistent' ? option : null
visit(tree, 'emphasis', (node) => {
const start = pointStart(node).offset
if (markers[preferred] !== true) {
file.fail(
'Incorrect emphasis marker `' +
preferred +
"`: use either `'consistent'`, `'*'`, or `'_'`"
)
}
if (typeof start === 'number') {
const marker = /** @type {Marker} */ (value.charAt(start))
visit(tree, 'emphasis', visitor)
function visitor(node) {
var marker
if (!generated(node)) {
marker = contents.charAt(position.start(node).offset)
if (preferred) {
if (marker !== preferred) {
file.message(
'Emphasis should use `' + preferred + '` as a marker',
node
)
if (option === 'consistent') {
option = marker
} else if (marker !== option) {
file.message('Emphasis should use `' + option + '` as a marker', node)
}
} else {
preferred = marker
}
}
})
}
}
)
export default remarkLintEmphasisMarker
{
"name": "remark-lint-emphasis-marker",
"version": "2.0.1",
"version": "3.0.0",
"description": "remark-lint rule to warn when emphasis markers violate the given style",

@@ -24,12 +24,27 @@ "license": "MIT",

],
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [
"index.d.ts",
"index.js"
],
"dependencies": {
"unified-lint-rule": "^1.0.0",
"unist-util-generated": "^1.1.0",
"unist-util-position": "^3.0.0",
"unist-util-visit": "^2.0.0"
"@types/mdast": "^3.0.0",
"unified": "^10.0.0",
"unified-lint-rule": "^2.0.0",
"unist-util-position": "^4.0.0",
"unist-util-visit": "^4.0.0"
},
"xo": false
"scripts": {
"build": "rimraf \"*.d.ts\" && tsc && type-coverage"
},
"xo": false,
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true,
"ignoreCatch": true
}
}

@@ -129,2 +129,5 @@ <!--This file is generated-->

This package is [ESM only][esm]:
Node 12+ is needed to use it and it must be `imported`ed instead of `required`d.
[npm][]:

@@ -136,2 +139,5 @@

This package exports no identifiers.
The default export is `remarkLintEmphasisMarker`.
## Use

@@ -163,10 +169,13 @@

```diff
var remark = require('remark')
var report = require('vfile-reporter')
import {remark} from 'remark'
import {reporter} from 'vfile-reporter'
import remarkLint from 'remark-lint'
import remarkLintEmphasisMarker from 'remark-lint-emphasis-marker'
remark()
.use(require('remark-lint'))
+ .use(require('remark-lint-emphasis-marker'))
.process('_Emphasis_ and **importance**', function (err, file) {
console.error(report(err || file))
.use(remarkLint)
+ .use(remarkLintEmphasisMarker)
.process('_Emphasis_ and **importance**')
.then((file) => {
console.error(reporter(file))
})

@@ -189,5 +198,5 @@ ```

[build-badge]: https://img.shields.io/travis/remarkjs/remark-lint/main.svg
[build-badge]: https://github.com/remarkjs/remark-lint/workflows/main/badge.svg
[build]: https://travis-ci.org/remarkjs/remark-lint
[build]: https://github.com/remarkjs/remark-lint/actions

@@ -212,6 +221,8 @@ [coverage-badge]: https://img.shields.io/codecov/c/github/remarkjs/remark-lint.svg

[chat-badge]: https://img.shields.io/badge/chat-spectrum.svg
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://spectrum.chat/unified/remark
[chat]: https://github.com/remarkjs/remark/discussions
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[npm]: https://docs.npmjs.com/cli/install

@@ -218,0 +229,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc