Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lloeki committed Aug 14, 2015
0 parents commit cc31bb3
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
npm-debug.log
node_modules
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
linter-markdownlint
=========================

This linter plugin for [Linter](https://github.com/AtomLinter/Linter) provides an interface to [markdownlint](https://github.com/mivok/markdownlint). It will be used with files that have the “Markdown” syntax.

## Installation
Linter package must be installed in order to use this plugin. If Linter is not installed, please follow the instructions [here](https://github.com/AtomLinter/Linter).

### mdl installation
Before using this plugin, you must ensure that `mdl` is installed on your system. To install `mdl`, do the following:

1. Install [ruby](https://www.ruby-lang.org/).

2. Install [markdownlint](https://github.com/mivok/markdownlint) by typing the following in a terminal:
```
gem install mdl
```

Now you can proceed to install the linter-markdownlint plugin.

### Plugin installation
```
$ apm install linter-markdownlint
```

## Settings
You can configure linter-markdownlint by editing ~/.atom/config.cson (choose Open Your Config in Atom menu):

```
'linter-markdownlint':
'executableDir': null # markdownlint directory path.
'binaryName': mdl # mdl binary name.
```
Run `which mdl` to find the path,
if you using rbenv run `rbenv which mdl`
76 changes: 76 additions & 0 deletions lib/init.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{BufferedProcess, CompositeDisposable} = require 'atom'

class Parser
@match: (line) ->
if m = /(.+):([0-9]+): +(MD[0-9]{3}) +(.+)/.exec line
type: 'Error'
message: "#{m[3]}: #{m[4]}"
lineStart: m[2]
lineEnd: m[2]
charStart: 1
charEnd: 1
@parse: (data) =>
errors = (@match(line) for line in data)
errors = (error for error in errors when error?)
if errors.length == 0
passed: true
else
passed: false
errors: errors

class Command
@setExecutablePath: (path) =>
@executablePath = path

@getExecutablePath: =>
@executablePath || 'mdl'

module.exports =
config:
executablePath:
type: 'string'
default: 'mdl'
description: 'Path to mdl executable'
activate: ->
@subscriptions = new CompositeDisposable
@subscriptions.add atom.config.observe 'linter-example.executablePath',
(executablePath) ->
Command.setExecutablePath(executablePath)
deactivate: ->
@subscriptions.dispose()
provideLinter: ->
provider =
grammarScopes: ['source.gfm', 'source.pfm']
scope: 'file'
lintOnFly: false
lint: (TextEditor) =>
return new Promise (resolve, reject) =>
filePath = TextEditor.getPath()
lines = []
console.log Command.getExecutablePath()
process = new BufferedProcess
command: Command.getExecutablePath()
args: [filePath]
stdout: (data) ->
lines.push(line) for line in data.split('\n')
exit: (code) ->
return resolve [] if code is 0
info = Parser.parse lines
return resolve [] unless info?
return resolve [] if info.passed
resolve info.errors.map (error) ->
type: error.type,
text: error.message,
filePath: error.file or filePath,
range: [
# Atom expects ranges to be 0-based
[error.lineStart - 1, error.charStart - 1],
[error.lineEnd - 1, error.charEnd]
]

process.onWillThrowError ({error,handle}) ->
atom.notifications.addError "Failed to run #{@executablePath}",
detail: "#{error.message}"
dismissable: true
handle()
resolve []
22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "linter-markdownlint",
"activationCommands": {},
"main": "./lib/init",
"version": "1.0.0",
"description": "Lint Markdown with mdl",
"keywords": ["linter", "mdl", "markdown", "markdownlint"],
"activationCommands": {},
"repository": "https://github.com/lloeki/linter-markdownlint",
"license": "MIT",
"engines": {
"atom": ">=1.0.0 <2.0.0"
},
"dependencies": {},
"providedServices": {
"linter": {
"versions": {
"1.0.0": "provideLinter"
}
}
}
}
13 changes: 13 additions & 0 deletions test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# foo

## bar
lorem ipsum

# baz

foo
---

1. foo
2. bar
baz

0 comments on commit cc31bb3

Please sign in to comment.