-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrites linter-markdownlint to support Linter Provider v2
- Supports Linter 2.3.0 and up. Closes #10 - Adds setting to customize the severity: error (by default), warning and info. Closes #9 - Rewrites package in Javascript / Drops Coffescript
- Loading branch information
1 parent
22636b3
commit 827bf1c
Showing
5 changed files
with
142 additions
and
81 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,133 @@ | ||
'use babel'; | ||
|
||
const { BufferedProcess, CompositeDisposable } = require('atom'); | ||
|
||
export const config = { | ||
executablePath: { | ||
type: 'string', | ||
default: 'mdl', | ||
description: 'Path to mdl executable', | ||
}, | ||
severity: { | ||
type: 'string', | ||
default: 'error', | ||
enum: [ | ||
{ value: 'error', description: 'Error' }, | ||
{ value: 'warning', description: 'Warning' }, | ||
{ value: 'info', description: 'Info' }, | ||
], | ||
description: 'Sets the severity of mdl findings', | ||
}, | ||
}; | ||
|
||
class Command { | ||
static setExecutablePath(path) { | ||
this.executablePath = path; | ||
} | ||
|
||
static getExecutablePath() { | ||
return this.executablePath || config.executablePath.default; | ||
} | ||
|
||
static setSeverity(severity) { | ||
this.severity = severity; | ||
} | ||
|
||
static getSeverity() { | ||
return this.severity || config.severity.default; | ||
} | ||
} | ||
|
||
class Parser { | ||
static match(line) { | ||
// Example line: /absolute/path/file.md:3: MD013 Line length | ||
const match = /(.+):([0-9]+): +(MD[0-9]{3}) +(.+)/.exec(line); | ||
|
||
if (match) { | ||
const text = `${match[3]}: ${match[4]}`; | ||
return { | ||
severity: Command.getSeverity(), | ||
location: { | ||
file: match[1], | ||
position: [[Number(match[2]) - 1, 0], [Number(match[2]) - 1, 0]], | ||
}, | ||
excerpt: text, | ||
description: text, | ||
}; | ||
} | ||
|
||
return undefined; | ||
} | ||
|
||
static parse(data) { | ||
const errors = data.map(line => Parser.match(line)).filter(Boolean); | ||
if (errors.length === 0) { | ||
return { passed: true }; | ||
} return { passed: false, errors }; | ||
} | ||
} | ||
|
||
export function activate() { | ||
this.subscriptions = new CompositeDisposable(); | ||
this.subscriptions.add( | ||
atom.config.observe( | ||
'linter-markdownlint.executablePath', | ||
executablePath => Command.setExecutablePath(executablePath), | ||
), | ||
); | ||
|
||
this.subscriptions.add( | ||
atom.config.observe( | ||
'linter-markdownlint.severity', | ||
severity => Command.setSeverity(severity), | ||
), | ||
); | ||
} | ||
|
||
export function deactivate() { | ||
this.subscriptions.dispose(); | ||
} | ||
|
||
export function provideLinter() { | ||
return { | ||
name: 'markdownlint', | ||
scope: 'file', | ||
lintsOnChange: false, | ||
grammarScopes: ['source.gfm', 'source.pfm'], | ||
lint(textEditor) { | ||
const editorPath = textEditor.getPath(); | ||
const cwd = atom.project.relativizePath(editorPath)[0]; | ||
|
||
return new Promise(((resolve) => { | ||
const lines = []; | ||
const process = new BufferedProcess({ | ||
options: { cwd }, | ||
command: Command.getExecutablePath(), | ||
args: [editorPath], | ||
stdout(data) { | ||
data.split('\n').forEach(line => lines.push(line)); | ||
}, | ||
exit(code) { | ||
if (code === 0) { | ||
return resolve([]); | ||
} | ||
const info = Parser.parse(lines); | ||
if (info == null || info.passed) { | ||
return resolve([]); | ||
} | ||
return resolve(info.errors); | ||
}, | ||
}); | ||
|
||
process.onWillThrowError((arg) => { | ||
const { error, handle } = arg; | ||
atom.notifications.addError(`Failed to run ${this.executablePath}`, { | ||
detail: `${error.message}`, dismissable: true, | ||
}); | ||
handle(); | ||
return resolve([]); | ||
}); | ||
})); | ||
}, | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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