remark-lint-no-shell-dollars
Advanced tools
Comparing version 1.0.1 to 1.0.2
58
index.js
@@ -24,2 +24,7 @@ /** | ||
* | ||
* Some empty code: | ||
* | ||
* ```command | ||
* ``` | ||
* | ||
* It’s fine to use dollars in non-shell code. | ||
@@ -43,10 +48,12 @@ * | ||
'use strict'; | ||
'use strict' | ||
var rule = require('unified-lint-rule'); | ||
var visit = require('unist-util-visit'); | ||
var generated = require('unist-util-generated'); | ||
var rule = require('unified-lint-rule') | ||
var visit = require('unist-util-visit') | ||
var generated = require('unist-util-generated') | ||
module.exports = rule('remark-lint:no-shell-dollars', noShellDollars); | ||
module.exports = rule('remark-lint:no-shell-dollars', noShellDollars) | ||
var reason = 'Do not use dollar signs before shell-commands' | ||
/* List of shell script file extensions (also used as code | ||
@@ -67,29 +74,34 @@ * flags for syntax highlighting on GitHub): | ||
'zsh' | ||
]; | ||
] | ||
function noShellDollars(ast, file) { | ||
visit(ast, 'code', visitor); | ||
function noShellDollars(tree, file) { | ||
visit(tree, 'code', visitor) | ||
function visitor(node) { | ||
var language = node.lang; | ||
var value = node.value; | ||
var warn; | ||
var lines | ||
var line | ||
var length | ||
var index | ||
if (!language || generated(node)) { | ||
return; | ||
} | ||
/* Check both known shell-code and unknown code. */ | ||
if (flags.indexOf(language) !== -1) { | ||
warn = value.length && value.split('\n').every(check); | ||
if (!generated(node) && node.lang && flags.indexOf(node.lang) !== -1) { | ||
lines = node.value.split('\n') | ||
length = lines.length | ||
index = -1 | ||
if (warn) { | ||
file.message('Do not use dollar signs before shell-commands', node); | ||
if (length <= 1) { | ||
return | ||
} | ||
while (++index < length) { | ||
line = lines[index] | ||
if (line.trim() && !line.match(/^\s*\$\s*/)) { | ||
return | ||
} | ||
} | ||
file.message(reason, node) | ||
} | ||
} | ||
function check(line) { | ||
return Boolean(!line.trim() || line.match(/^\s*\$\s*/)); | ||
} | ||
} |
{ | ||
"name": "remark-lint-no-shell-dollars", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "remark-lint rule to warn when shell code is prefixed by dollars", | ||
@@ -13,4 +13,4 @@ "license": "MIT", | ||
], | ||
"repository": "https://github.com/wooorm/remark-lint/tree/master/packages/remark-lint-no-shell-dollars", | ||
"bugs": "https://github.com/wooorm/remark-lint/issues", | ||
"repository": "https://github.com/remarkjs/remark-lint/tree/master/packages/remark-lint-no-shell-dollars", | ||
"bugs": "https://github.com/remarkjs/remark-lint/issues", | ||
"author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)", | ||
@@ -17,0 +17,0 @@ "contributors": [ |
@@ -15,3 +15,3 @@ <!--This file is generated--> | ||
| ------ | ------- | | ||
| [`remark-preset-lint-markdown-style-guide`](https://github.com/wooorm/remark-lint/tree/master/packages/remark-preset-lint-markdown-style-guide) | | | ||
| [`remark-preset-lint-markdown-style-guide`](https://github.com/remarkjs/remark-lint/tree/master/packages/remark-preset-lint-markdown-style-guide) | | | ||
@@ -25,18 +25,23 @@ ## Example | ||
````markdown | ||
```sh | ||
echo a | ||
echo a > file | ||
``` | ||
```sh | ||
echo a | ||
echo a > file | ||
``` | ||
```zsh | ||
$ echo a | ||
a | ||
$ echo a > file | ||
``` | ||
```zsh | ||
$ echo a | ||
a | ||
$ echo a > file | ||
``` | ||
It’s fine to use dollars in non-shell code. | ||
Some empty code: | ||
```js | ||
$('div').remove(); | ||
``` | ||
```command | ||
``` | ||
It’s fine to use dollars in non-shell code. | ||
```js | ||
$('div').remove(); | ||
``` | ||
```` | ||
@@ -53,6 +58,6 @@ | ||
````markdown | ||
```bash | ||
$ echo a | ||
$ echo a > file | ||
``` | ||
```bash | ||
$ echo a | ||
$ echo a > file | ||
``` | ||
```` | ||
@@ -111,2 +116,2 @@ | ||
[MIT](https://github.com/wooorm/remark-lint/blob/master/LICENSE) © [Titus Wormer](http://wooorm.com) | ||
[MIT](https://github.com/remarkjs/remark-lint/blob/master/LICENSE) © [Titus Wormer](http://wooorm.com) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
4458
92
114