Skip to content

Commit

Permalink
Update for changes in remark@6.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Aug 21, 2016
1 parent 77709f5 commit 6196124
Show file tree
Hide file tree
Showing 61 changed files with 94 additions and 98 deletions.
2 changes: 1 addition & 1 deletion doc/external.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function rule(ast, file, setting) {
visit(ast, 'code', function (node) {
/* Emit a linting message, only for JS code though. */
if (valid.indexOf(node.lang) !== -1 && node.lang !== pref) {
file.warn(
file.message(
'JavaScript code blocks should use `' + pref + '` as a ' +
'language flag, not `' + node.lang + '`',
node
Expand Down
10 changes: 5 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,22 +151,22 @@ function ruleFactory(id, rule, severity, options) {
var fatal = severity === 2;

return function (ast, file, next) {
var scope = file.namespace('remark-lint');
var scope = file.data;

/* Track new messages per file. */
scope.index = file.messages.length;
scope.remarkLintIndex = file.messages.length;

fn(ast, file, options, function (err) {
var messages = file.messages;
var message;

while (scope.index < messages.length) {
message = messages[scope.index];
while (scope.remarkLintIndex < messages.length) {
message = messages[scope.remarkLintIndex];
message.ruleId = id;
message.source = SOURCE;
message.fatal = fatal;

scope.index++;
scope.remarkLintIndex++;
}

next(err);
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/blockquote-indentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function blockquoteIndentation(ast, file, preferred) {
diff = Math.abs(diff);

if (diff !== 0) {
file.warn(
file.message(
word + ' ' + diff + ' ' + plural('space', diff) +
' between blockquote and content',
position.start(node.children[0])
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/checkbox-character-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ function checkboxCharacterStyle(ast, file, preferred) {
} else if (character !== style) {
stop = initial + value.length;

file.warn(
file.message(
type.charAt(0).toUpperCase() + type.slice(1) +
' checkboxes should use `' + style + '` as a marker',
{
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/checkbox-content-indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function checkboxContentIndent(ast, file) {
return;
}

file.warn('Checkboxes should be followed by a single character', {
file.message('Checkboxes should be followed by a single character', {
start: location.toPosition(final - value.length + 1),
end: location.toPosition(final)
});
Expand Down
3 changes: 1 addition & 2 deletions lib/rules/code-block-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ function codeBlockStyle(ast, file, preferred) {

if (STYLES[preferred] !== true) {
file.fail('Invalid code block style `' + preferred + '`: use either `\'consistent\'`, `\'fenced\'`, or `\'indented\'`');
return;
}

visit(ast, 'code', function (node) {
Expand All @@ -138,7 +137,7 @@ function codeBlockStyle(ast, file, preferred) {
if (!preferred) {
preferred = current;
} else if (preferred !== current) {
file.warn('Code blocks should be ' + preferred, node);
file.message('Code blocks should be ' + preferred, node);
}
});

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/definition-case.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function definitionCase(ast, file) {
label = contents.slice(start, end).match(LABEL)[1];

if (label !== label.toLowerCase()) {
file.warn('Do not use upper-case characters in definition labels', node);
file.message('Do not use upper-case characters in definition labels', node);
}
}
}
2 changes: 1 addition & 1 deletion lib/rules/definition-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function definitionSpacing(ast, file) {
label = contents.slice(start, end).match(LABEL)[1];

if (/[ \t\n]{2,}/.test(label)) {
file.warn('Do not use consecutive white-space in definition labels', node);
file.message('Do not use consecutive white-space in definition labels', node);
}
}
}
3 changes: 1 addition & 2 deletions lib/rules/emphasis-marker.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ function emphasisMarker(ast, file, preferred) {

if (MARKERS[preferred] !== true) {
file.fail('Invalid emphasis marker `' + preferred + '`: use either `\'consistent\'`, `\'*\'`, or `\'_\'`');
return;
}

visit(ast, 'emphasis', function (node) {
Expand All @@ -96,7 +95,7 @@ function emphasisMarker(ast, file, preferred) {

if (preferred) {
if (marker !== preferred) {
file.warn('Emphasis should use `' + preferred + '` as a marker', node);
file.message('Emphasis should use `' + preferred + '` as a marker', node);
}
} else {
preferred = marker;
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/fenced-code-flag.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ function fencedCodeFlag(ast, file, preferred) {

if (node.lang) {
if (flags.length && flags.indexOf(node.lang) === -1) {
file.warn('Invalid code-language flag', node);
file.message('Invalid code-language flag', node);
}
} else if (/^ {0,3}([~`])\1{2,}/.test(value) && !allowEmpty) {
file.warn('Missing code-language flag', node);
file.message('Missing code-language flag', node);
}
});
}
3 changes: 1 addition & 2 deletions lib/rules/fenced-code-marker.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ function fencedCodeMarker(ast, file, preferred) {

if (MARKERS[preferred] !== true) {
file.fail('Invalid fenced code marker `' + preferred + '`: use either `\'consistent\'`, `` \'`\' ``, or `\'~\'`');
return;
}

visit(ast, 'code', function (node) {
Expand All @@ -107,7 +106,7 @@ function fencedCodeMarker(ast, file, preferred) {

if (preferred) {
if (marker !== preferred) {
file.warn('Fenced code should use ' + preferred + ' as a marker', node);
file.message('Fenced code should use ' + preferred + ' as a marker', node);
}
} else {
preferred = marker;
Expand Down
11 changes: 8 additions & 3 deletions lib/rules/file-extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@ module.exports = fileExtension;
* extension.
*/
function fileExtension(ast, file, preferred) {
var ext = file.extension;
var ext = file.extname;

if (ext) {
ext = ext.slice(1);
}

preferred = typeof preferred === 'string' ? preferred : 'md';

if (ext !== '' && ext !== preferred) {
file.warn('Invalid extension: use `' + preferred + '`');
if (ext && ext !== preferred) {
console.log('e: ', [ext, preferred, file.extname], file);
file.message('Invalid extension: use `' + preferred + '`');
}
}
2 changes: 1 addition & 1 deletion lib/rules/final-definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function finalDefinition(ast, file) {

if (node.type === 'definition') {
if (last !== null && last > line) {
file.warn('Move definitions to the end of the file (after the node at line `' + last + '`)', node);
file.message('Move definitions to the end of the file (after the node at line `' + last + '`)', node);
}
} else if (last === null) {
last = line;
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/final-newline.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ function finalNewline(ast, file) {
var last = contents.length - 1;

if (last > -1 && contents.charAt(last) !== '\n') {
file.warn('Missing newline character at end of file');
file.message('Missing newline character at end of file');
}
}
2 changes: 1 addition & 1 deletion lib/rules/first-heading-level.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function firstHeadingLevel(ast, file, preferred) {
}

if (node.depth !== style) {
file.warn('First heading level should be `' + style + '`', node);
file.message('First heading level should be `' + style + '`', node);
}

return false;
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/hard-break-spaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function hardBreakSpaces(ast, file) {
value = contents.slice(start, end).split('\n', 1)[0].replace(/\r$/, '');

if (value.length > 2) {
file.warn('Use two spaces for hard line breaks', node);
file.message('Use two spaces for hard line breaks', node);
}
});
}
2 changes: 1 addition & 1 deletion lib/rules/heading-increment.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function headingIncrement(ast, file) {
}

if (prev && depth > prev + 1) {
file.warn('Heading levels should increment by one level at a time', node);
file.message('Heading levels should increment by one level at a time', node);
}

prev = depth;
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/heading-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function headingStyle(ast, file, preferred) {

if (preferred) {
if (style(node, preferred) !== preferred) {
file.warn('Headings should use ' + preferred, node);
file.message('Headings should use ' + preferred, node);
}
} else {
preferred = style(node, preferred);
Expand Down
3 changes: 1 addition & 2 deletions lib/rules/link-title-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ function linkTitleStyle(ast, file, preferred) {

if (MARKERS[preferred] !== true) {
file.fail('Invalid link title style marker `' + preferred + '`: use either `\'consistent\'`, `\'"\'`, `\'\\\'\'`, or `\'()\'`');
return;
}

visit(ast, 'link', validate);
Expand Down Expand Up @@ -149,7 +148,7 @@ function linkTitleStyle(ast, file, preferred) {
preferred = character;
} else if (preferred !== character) {
pos = location.toPosition(last + 1);
file.warn('Titles should use `' + (preferred === ')' ? '()' : preferred) + '` as a quote', pos);
file.message('Titles should use `' + (preferred === ')' ? '()' : preferred) + '` as a quote', pos);
}
}
}
2 changes: 1 addition & 1 deletion lib/rules/list-item-bullet-indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function listItemBulletIndent(ast, file) {
if (indent !== 0) {
initial = start(head);

file.warn('Incorrect indentation before bullet: remove ' + indent + ' ' + plural('space', indent), {
file.message('Incorrect indentation before bullet: remove ' + indent + ' ' + plural('space', indent), {
line: initial.line,
column: initial.column - indent
});
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/list-item-content-indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function listItemContentIndent(ast, file) {

diff = Math.abs(diff);

file.warn(
file.message(
'Don’t use mixed indentation for children, ' + word +
' ' + diff + ' ' + plural('space', diff),
{
Expand Down
3 changes: 1 addition & 2 deletions lib/rules/list-item-indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ function listItemIndent(ast, file, preferred) {

if (STYLES[preferred] !== true) {
file.fail('Invalid list-item indent style `' + preferred + '`: use either `\'tab-size\'`, `\'space\'`, or `\'mixed\'`');
return;
}

visit(ast, 'list', function (node) {
Expand Down Expand Up @@ -148,7 +147,7 @@ function listItemIndent(ast, file, preferred) {

diff = Math.abs(diff);

file.warn(
file.message(
'Incorrect list-item indent: ' + word +
' ' + diff + ' ' + plural('space', diff),
start(head)
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/list-item-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ function listItemSpacing(ast, file) {
* match the list's state. */
if (isTight !== isTightList) {
if (type === 'loose') {
file.warn('Missing new line after list item', {
file.message('Missing new line after list item', {
start: end(item),
end: start(next)
});
} else {
file.warn('Extraneous new line after list item', {
file.message('Extraneous new line after list item', {
start: end(item),
end: start(next)
});
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/maximum-heading-length.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function maximumHeadingLength(ast, file, preferred) {
}

if (toString(node).length > preferred) {
file.warn('Use headings shorter than `' + preferred + '`', node);
file.message('Use headings shorter than `' + preferred + '`', node);
}
});
}
2 changes: 1 addition & 1 deletion lib/rules/maximum-line-length.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function maximumLineLength(ast, file, preferred) {
lineLength = matrix[index].length;

if (lineLength > style) {
file.warn('Line must be at most ' + style + ' characters', {
file.message('Line must be at most ' + style + ' characters', {
line: index + 1,
column: lineLength + 1
});
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-auto-link-without-protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function noAutoLinkWithoutProtocol(ast, file) {
}

if (initial === head - 1 && final === tail + 1 && !hasProtocol(node)) {
file.warn('All automatic links must start with a protocol', node);
file.message('All automatic links must start with a protocol', node);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-blockquote-without-caret.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function noBlockquoteWithoutCaret(ast, file) {
}
}

file.warn('Missing caret in blockquote', {
file.message('Missing caret in blockquote', {
line: line,
column: column
});
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-consecutive-blank-lines.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function noConsecutiveBlankLines(ast, file) {
diff = Math.abs(diff) - max;

if (diff > 0) {
file.warn('Remove ' + diff + ' ' + plural('line', diff) + ' ' + word + ' node', end);
file.message('Remove ' + diff + ' ' + plural('line', diff) + ' ' + word + ' node', end);
}
}
}
2 changes: 1 addition & 1 deletion lib/rules/no-duplicate-definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function noDuplicateDefinitions(ast, file) {
if (duplicate && duplicate.type) {
pos = position.start(duplicate);

file.warn(
file.message(
'Do not use definitions with the same identifier (' +
pos.line + ':' + pos.column + ')',
node
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-duplicate-headings.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function noDuplicateHeadings(ast, file) {
if (duplicate && duplicate.type === 'heading') {
pos = position.start(duplicate);

file.warn(
file.message(
'Do not use headings with similar content (' +
pos.line + ':' + pos.column + ')',
node
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-emphasis-as-heading.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function noEmphasisAsHeading(ast, file) {
children.length === 1 &&
(child.type === 'emphasis' || child.type === 'strong')
) {
file.warn('Don’t use emphasis to introduce a section, use a heading', node);
file.message('Don’t use emphasis to introduce a section, use a heading', node);
}
});
}
4 changes: 2 additions & 2 deletions lib/rules/no-file-name-articles.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ module.exports = noFileNameArticles;
* @param {File} file - Virtual file.
*/
function noFileNameArticles(ast, file) {
var match = file.filename && file.filename.match(/^(the|an?)\b/i);
var match = file.stem && file.stem.match(/^(the|an?)\b/i);

if (match) {
file.warn('Do not start file names with `' + match[0] + '`');
file.message('Do not start file names with `' + match[0] + '`');
}
}
4 changes: 2 additions & 2 deletions lib/rules/no-file-name-consecutive-dashes.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = noFileNameConsecutiveDashes;
* @param {File} file - Virtual file.
*/
function noFileNameConsecutiveDashes(ast, file) {
if (file.filename && /-{2,}/.test(file.filename)) {
file.warn('Do not use consecutive dashes in a file name');
if (file.stem && /-{2,}/.test(file.stem)) {
file.message('Do not use consecutive dashes in a file name');
}
}
4 changes: 2 additions & 2 deletions lib/rules/no-file-name-irregular-characters.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ function noFileNameIrregularCharacters(ast, file, preferred) {
expression = new RegExp('[^' + expression + ']');
}

match = file.filename && file.filename.match(expression);
match = file.stem && file.stem.match(expression);

if (match) {
file.warn('Do not use `' + match[0] + '` in a file name');
file.message('Do not use `' + match[0] + '` in a file name');
}
}
Loading

0 comments on commit 6196124

Please sign in to comment.