Skip to content

Commit

Permalink
Merge bcefe6c into fb4ec3a
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavnikolaj committed Mar 27, 2017
2 parents fb4ec3a + bcefe6c commit 234d6d7
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 28 deletions.
30 changes: 24 additions & 6 deletions lib/linting.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,30 @@ function lint (textEditor, reportError) {
if (!report) return []

const { filePath } = report
return report.messages.map(({ message: text, line, column, severity, source }) => ({
type: severity === 2 ? 'Error' : 'Warning',
text,
filePath,
range: getRange(line, column, source)
}))
return report.messages.map(({ message: excerpt, line, column, severity, source, fix }) => {
const result = {
severity: severity === 2 ? 'error' : 'warning',
excerpt,
location: {
file: filePath,
position: getRange(line, column, source)
}
}

if (fix) {
result.solutions = [
{
position: [
textEditor.getBuffer().positionForCharacterIndex(fix.range[0]),
textEditor.getBuffer().positionForCharacterIndex(fix.range[1])
],
replaceWith: fix.text
}
]
}

return result
})
})
.catch(err => {
if (!suppressError(err)) reportError(err)
Expand Down
2 changes: 1 addition & 1 deletion lib/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ exports.provideLinter = () => ({
name: 'standard-engine',
grammarScopes: GRAMMAR_SCOPES,
scope: 'file',
lintOnFly: true,
lintsOnChange: true,
lint (textEditor) {
return lint(textEditor, reportError)
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"providedServices": {
"linter": {
"versions": {
"1.0.0": "provideLinter"
"2.0.0": "provideLinter"
}
}
},
Expand Down
40 changes: 24 additions & 16 deletions test/lib/linting.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,28 +75,36 @@ describe('lib/linting', () => {
})
return expect(linting.lint(textEditor), 'to be fulfilled').then(report => expect(report, 'to equal', [
{
type: 'Error',
text: 'Newline required at end of file but not found.',
filePath,
range: [ [ 0, 0 ], [ 0, 1 ] ]
severity: 'error',
excerpt: 'Newline required at end of file but not found.',
location: {
file: filePath,
position: [ [ 0, 0 ], [ 0, 1 ] ]
}
},
{
type: 'Warning',
text: '"foo" is defined but never used',
filePath,
range: [ [ 0, 1 ], [ 0, 4 ] ]
severity: 'warning',
excerpt: '"foo" is defined but never used',
location: {
file: filePath,
position: [ [ 0, 1 ], [ 0, 4 ] ]
}
},
{
type: 'Error',
text: 'Strings must use singlequote.',
filePath,
range: [ [ 0, 1 ], [ 0, 10 ] ]
severity: 'error',
excerpt: 'Strings must use singlequote.',
location: {
file: filePath,
position: [ [ 0, 1 ], [ 0, 10 ] ]
}
},
{
type: 'Error',
text: 'Made up message to test fallback code paths',
filePath,
range: [ [ 0, 0 ], [ 0, 0 ] ]
severity: 'error',
excerpt: 'Made up message to test fallback code paths',
location: {
file: filePath,
position: [ [ 0, 0 ], [ 0, 0 ] ]
}
}
]))
})
Expand Down
10 changes: 6 additions & 4 deletions test/lib/register.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ const linter = plugin.provideLinter()
const lint = linter.lint.bind(linter)

expect.addAssertion('to be a valid lint report', (expect, subject) => expect(subject, 'to have items satisfying', {
type: expect.it('to be a string').and('not to be empty'),
text: expect.it('to be a string').and('not to be empty'),
filePath: expect.it('to be a string').and('to match', /\.js$/),
range: expect.it('to have items satisfying', 'to have items satisfying', 'to be a number')
severity: expect.it('to be a string').and('not to be empty').and('to match', /^[a-z]+$/),
excerpt: expect.it('to be a string').and('not to be empty'),
location: expect.it('to exhaustively satisfy', {
file: expect.it('to be a string').and('to match', /\.js$/),
position: expect.it('to have items satisfying', 'to have items satisfying', 'to be a number')
})
}))

describe('linter-js-standard-engine', () => {
Expand Down

0 comments on commit 234d6d7

Please sign in to comment.