forked from platanus/hound-linters
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
765 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"plugins": ["remark-preset-lint-recommended"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require "linters/base/options" | ||
require "linters/remark/tokenizer" | ||
|
||
module Linters | ||
module Remark | ||
class Options | ||
def command(filename) | ||
cmd = "remark-cli/cli.js #{filename}" | ||
"NODE_PATH=#{node_modules_path} #{File.join(node_modules_path, cmd)}" | ||
end | ||
|
||
def config_filename | ||
".remarkrc" | ||
end | ||
|
||
def tokenizer | ||
Tokenizer.new | ||
end | ||
|
||
def config_content(content) | ||
if JSON.parse(content).any? | ||
content | ||
else | ||
config(content).to_json | ||
end | ||
end | ||
|
||
private | ||
|
||
def node_modules_path | ||
File.join(current_path, "node_modules") | ||
end | ||
|
||
def current_path | ||
File.expand_path("../../..", __dir__) | ||
end | ||
|
||
def config(content) | ||
Config.new(content: content, default_config_path: "config/remarkrc") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module Linters | ||
module Remark | ||
class Tokenizer | ||
VIOLATION_REGEX = /\A | ||
\s+ | ||
(?<line_number>\d+):(?<start_column>\d+) | ||
(-(?<end_line_number>\d+):(?<end_column>\d+))? | ||
\s{2,} | ||
(?:\e\[\d+m)? | ||
(?<violation_level>\w+)? | ||
(?:\e\[\d+m)? | ||
\s{2,} | ||
(?<message>.+?) | ||
\s{2,} | ||
(?<rule-name>.+?) | ||
\s{2,} | ||
(?<source>.+?) | ||
\z/x | ||
|
||
def parse(text) | ||
Linters::Tokenizer.new(text, VIOLATION_REGEX).parse | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
require "jobs/linters_job" | ||
|
||
RSpec.describe LintersJob, "for remark-lint" do | ||
include LintersHelper | ||
|
||
context "when file with .md extention contains violations" do | ||
it "reports violations" do | ||
expect_violations_in_file( | ||
content: content, | ||
filename: "foo/test.md", | ||
linter_name: "remark", | ||
violations: [ | ||
{ | ||
line: 1, | ||
message: "Incorrect list-item indent: add 2 spaces", | ||
}, | ||
{ | ||
line: 3, | ||
message: "Found reference to undefined definition", | ||
}, | ||
], | ||
) | ||
end | ||
end | ||
|
||
context "when custom configuraton is provided" do | ||
context "and plugins are an object" do | ||
it "respects the custom configuration" do | ||
config = <<~JSON | ||
{ | ||
"plugins": { | ||
"remark-preset-lint-recommended": true, | ||
"lint-list-item-indent": false | ||
} | ||
} | ||
JSON | ||
|
||
expect_violations_in_file( | ||
config: config, | ||
content: content, | ||
filename: "foo/test.md", | ||
linter_name: "remark", | ||
violations: [ | ||
{ | ||
line: 3, | ||
message: "Found reference to undefined definition", | ||
}, | ||
], | ||
) | ||
end | ||
end | ||
|
||
context "and plugins are an array" do | ||
it "respects the custom configuration" do | ||
config = <<~JSON | ||
{ | ||
"plugins": [ | ||
"remark-preset-lint-recommended", | ||
["lint-list-item-indent", false] | ||
] | ||
} | ||
JSON | ||
|
||
expect_violations_in_file( | ||
config: config, | ||
content: content, | ||
filename: "foo/test.md", | ||
linter_name: "remark", | ||
violations: [ | ||
{ | ||
line: 3, | ||
message: "Found reference to undefined definition", | ||
}, | ||
], | ||
) | ||
end | ||
end | ||
end | ||
|
||
def content | ||
<<~MD | ||
* Hello | ||
[World][] | ||
MD | ||
end | ||
end |
Oops, something went wrong.