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

remark-lint-code-block-style

Package Overview
Dependencies
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remark-lint-code-block-style - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

70

index.js

@@ -12,3 +12,3 @@ /**

* `'consistent'` detects the first used code block style and warns when
* subsequent code-blocks uses different styles.
* subsequent code blocks uses different styles.
*

@@ -27,3 +27,3 @@ * ## Fix

*
* @example {"setting": "indented", "name": "valid.md"}
* @example {"setting": "indented", "name": "ok.md"}
*

@@ -36,3 +36,3 @@ * alpha();

*
* @example {"setting": "indented", "name": "invalid.md", "label": "input"}
* @example {"setting": "indented", "name": "not-ok.md", "label": "input"}
*

@@ -49,3 +49,3 @@ * ```

*
* @example {"setting": "indented", "name": "invalid.md", "label": "output"}
* @example {"setting": "indented", "name": "not-ok.md", "label": "output"}
*

@@ -55,3 +55,3 @@ * 1:1-3:4: Code blocks should be indented

*
* @example {"setting": "fenced", "name": "valid.md"}
* @example {"setting": "fenced", "name": "ok.md"}
*

@@ -68,3 +68,3 @@ * ```

*
* @example {"setting": "fenced", "name": "invalid.md", "label": "input"}
* @example {"setting": "fenced", "name": "not-ok-fenced.md", "label": "input"}
*

@@ -77,3 +77,3 @@ * alpha();

*
* @example {"setting": "fenced", "name": "invalid.md", "label": "output"}
* @example {"setting": "fenced", "name": "not-ok-fenced.md", "label": "output"}
*

@@ -83,3 +83,3 @@ * 1:1-1:13: Code blocks should be fenced

*
* @example {"name": "invalid.md", "label": "input"}
* @example {"name": "not-ok-consistent.md", "label": "input"}
*

@@ -94,9 +94,9 @@ * alpha();

*
* @example {"name": "invalid.md", "label": "output"}
* @example {"name": "not-ok-consistent.md", "label": "output"}
*
* 5:1-7:4: Code blocks should be indented
*
* @example {"setting": "invalid", "name": "invalid.md", "label": "output", "config": {"positionless": true}}
* @example {"setting": "💩", "name": "not-ok-incorrect.md", "label": "output", "config": {"positionless": true}}
*
* 1:1: Invalid code block style `invalid`: use either `'consistent'`, `'fenced'`, or `'indented'`
* 1:1: Incorrect code block style `💩`: use either `'consistent'`, `'fenced'`, or `'indented'`
*/

@@ -118,11 +118,11 @@

function codeBlockStyle(tree, file, pref) {
function codeBlockStyle(tree, file, option) {
var contents = String(file)
var preferred =
typeof option === 'string' && option !== 'consistent' ? option : null
pref = typeof pref === 'string' && pref !== 'consistent' ? pref : null
if (styles[pref] !== true) {
if (styles[preferred] !== true) {
file.fail(
'Invalid code block style `' +
pref +
'Incorrect code block style `' +
preferred +
"`: use either `'consistent'`, `'fenced'`, or `'indented'`"

@@ -135,26 +135,26 @@ )

function visitor(node) {
var current = check(node)
var initial
var final
var current
if (current) {
if (!pref) {
pref = current
} else if (pref !== current) {
file.message('Code blocks should be ' + pref, node)
}
if (generated(node)) {
return null
}
}
// Get the style of `node`.
function check(node) {
var initial = start(node).offset
var final = end(node).offset
initial = start(node).offset
final = end(node).offset
if (generated(node)) {
return null
current =
node.lang || /^\s*([~`])\1{2,}/.test(contents.slice(initial, final))
? 'fenced'
: 'indented'
if (preferred) {
if (preferred !== current) {
file.message('Code blocks should be ' + preferred, node)
}
} else {
preferred = current
}
return node.lang || /^\s*([~`])\1{2,}/.test(contents.slice(initial, final))
? 'fenced'
: 'indented'
}
}
{
"name": "remark-lint-code-block-style",
"version": "1.0.3",
"description": "remark-lint rule to warn when code-blocks do not adhere to a given style",
"version": "1.0.4",
"description": "remark-lint rule to warn when code blocks do not adhere to a given style",
"license": "MIT",

@@ -10,2 +10,3 @@ "keywords": [

"rule",
"remark-lint-rule",
"code",

@@ -16,2 +17,6 @@ "block"

"bugs": "https://github.com/remarkjs/remark-lint/issues",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/unified"
},
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",

@@ -18,0 +23,0 @@ "contributors": [

@@ -18,3 +18,3 @@ <!--This file is generated-->

`'consistent'` detects the first used code block style and warns when
subsequent code-blocks uses different styles.
subsequent code blocks uses different styles.

@@ -44,3 +44,3 @@ ## Fix

##### `valid.md`
##### `ok.md`

@@ -63,3 +63,3 @@ When configured with `'indented'`.

##### `invalid.md`
##### `not-ok.md`

@@ -89,3 +89,3 @@ When configured with `'indented'`.

##### `valid.md`
##### `ok.md`

@@ -112,3 +112,3 @@ When configured with `'fenced'`.

##### `invalid.md`
##### `not-ok-fenced.md`

@@ -134,3 +134,3 @@ When configured with `'fenced'`.

##### `invalid.md`
##### `not-ok-consistent.md`

@@ -155,5 +155,5 @@ ###### In

##### `invalid.md`
##### `not-ok-incorrect.md`
When configured with `'invalid'`.
When configured with `'💩'`.

@@ -163,3 +163,3 @@ ###### Out

```text
1:1: Invalid code block style `invalid`: use either `'consistent'`, `'fenced'`, or `'indented'`
1:1: Incorrect code block style `💩`: use either `'consistent'`, `'fenced'`, or `'indented'`
```

@@ -180,12 +180,12 @@

```diff
...
"remarkConfig": {
"plugins": [
...
"lint",
+ "lint-code-block-style",
...
]
}
...
```

@@ -202,4 +202,4 @@

```diff
var remark = require('remark');
var report = require('vfile-reporter');
var remark = require('remark')
var report = require('vfile-reporter')

@@ -210,4 +210,4 @@ remark()

.process('_Emphasis_ and **importance**', function (err, file) {
console.error(report(err || file));
});
console.error(report(err || file))
})
```

@@ -221,4 +221,4 @@

This project has a [Code of Conduct][coc].
By interacting with this repository, organisation, or community you agree to
This project has a [code of conduct][coc].
By interacting with this repository, organization, or community you agree to
abide by its terms.

@@ -252,3 +252,3 @@

[chat-badge]: https://img.shields.io/badge/join%20the%20community-on%20spectrum-7b16ff.svg
[chat-badge]: https://img.shields.io/badge/chat-spectrum.svg

@@ -255,0 +255,0 @@ [chat]: https://spectrum.chat/unified/remark

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