remark-lint-linebreak-style
Advanced tools
Comparing version 1.0.1 to 1.0.2
66
index.js
@@ -13,2 +13,10 @@ /** | ||
* | ||
* ## Fix | ||
* | ||
* [`remark-stringify`](https://github.com/remarkjs/remark/tree/master/packages/remark-stringify) | ||
* always uses unix-style linebreaks. | ||
* | ||
* See [Using remark to fix your markdown](https://github.com/remarkjs/remark-lint#using-remark-to-fix-your-markdown) | ||
* on how to automatically fix warnings for this rule. | ||
* | ||
* @example {"name": "valid-consistent-as-windows.md"} | ||
@@ -41,42 +49,46 @@ * | ||
'use strict'; | ||
'use strict' | ||
var rule = require('unified-lint-rule'); | ||
var location = require('vfile-location'); | ||
var rule = require('unified-lint-rule') | ||
var location = require('vfile-location') | ||
module.exports = rule('remark-lint:linebreak-style', linebreakStyle); | ||
module.exports = rule('remark-lint:linebreak-style', linebreakStyle) | ||
var sequences = { | ||
unix: '\n', | ||
windows: '\r\n' | ||
}; | ||
var escaped = {unix: '\\n', windows: '\\r\\n'} | ||
var types = {true: 'windows', false: 'unix'} | ||
var escaped = { | ||
unix: '\\n', | ||
windows: '\\r\\n' | ||
}; | ||
function linebreakStyle(tree, file, pref) { | ||
var content = String(file) | ||
var position = location(content).toPosition | ||
var index = content.indexOf('\n') | ||
var type | ||
var reason | ||
function linebreakStyle(ast, file, preferred) { | ||
var content = String(file); | ||
var position = location(content).toPosition; | ||
var index = content.indexOf('\n'); | ||
var type; | ||
pref = typeof pref === 'string' && pref !== 'consistent' ? pref : null | ||
while (index !== -1) { | ||
type = content.charAt(index - 1) === '\r' ? 'windows' : 'unix'; | ||
type = types[content.charAt(index - 1) === '\r'] | ||
if (preferred) { | ||
if (sequences[preferred] !== sequences[type]) { | ||
file.message( | ||
'Expected linebreaks to be ' + preferred + ' (`' + escaped[preferred] + '`), ' + | ||
'not ' + type + ' (`' + escaped[type] + '`)', | ||
position(index) | ||
); | ||
if (pref) { | ||
if (pref !== type) { | ||
reason = | ||
'Expected linebreaks to be ' + | ||
pref + | ||
' (`' + | ||
escaped[pref] + | ||
'`), ' + | ||
'not ' + | ||
type + | ||
' (`' + | ||
escaped[type] + | ||
'`)' | ||
file.message(reason, position(index)) | ||
} | ||
} else { | ||
preferred = type; | ||
pref = type | ||
} | ||
index = content.indexOf('\n', index + 1); | ||
index = content.indexOf('\n', index + 1) | ||
} | ||
} |
{ | ||
"name": "remark-lint-linebreak-style", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "remark-lint rule to warn when linebreaks violate a given or detected style", | ||
@@ -18,4 +18,4 @@ "license": "MIT", | ||
], | ||
"repository": "https://github.com/wooorm/remark-lint/tree/master/packages/remark-lint-linebreak-style", | ||
"bugs": "https://github.com/wooorm/remark-lint/issues", | ||
"repository": "https://github.com/remarkjs/remark-lint/tree/master/packages/remark-lint-linebreak-style", | ||
"bugs": "https://github.com/remarkjs/remark-lint/issues", | ||
"author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)", | ||
@@ -22,0 +22,0 @@ "contributors": [ |
@@ -11,2 +11,10 @@ <!--This file is generated--> | ||
## Fix | ||
[`remark-stringify`](https://github.com/remarkjs/remark/tree/master/packages/remark-stringify) | ||
always uses unix-style linebreaks. | ||
See [Using remark to fix your markdown](https://github.com/remarkjs/remark-lint#using-remark-to-fix-your-markdown) | ||
on how to automatically fix warnings for this rule. | ||
## Presets | ||
@@ -129,2 +137,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
5595
82
137