-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added
lint
command to validate extension source
- Loading branch information
Showing
6 changed files
with
167 additions
and
5 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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/* @flow */ | ||
import build from './build'; | ||
import lint from './lint'; | ||
import run from './run'; | ||
import sign from './sign'; | ||
export default {build, run, sign}; | ||
export default {build, lint, run, sign}; |
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,28 @@ | ||
/* @flow */ | ||
import {createLinter as defaultLinterCreator} from '../util/es6-modules'; | ||
import {createLogger} from '../util/logger'; | ||
|
||
const log = createLogger(__filename); | ||
|
||
export default function lint( | ||
{verbose, sourceDir, selfHosted, boring, output, | ||
metadata, pretty}: Object, | ||
{createLinter=defaultLinterCreator}: Object): Promise { | ||
log.debug(`Running addons-linter on ${sourceDir}`); | ||
const linter = createLinter({ | ||
config: { | ||
logLevel: verbose ? 'debug' : 'fatal', | ||
stack: Boolean(verbose), | ||
pretty, | ||
metadata, | ||
output, | ||
boring, | ||
selfHosted, | ||
// This mimics the first command line argument from yargs, | ||
// which should be the directory to the extension. | ||
_: [sourceDir], | ||
}, | ||
runAsBinary: true, | ||
}); | ||
return linter.run(); | ||
} |
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 |
---|---|---|
@@ -1,11 +1,10 @@ | ||
/* | ||
* This is a terrible and sad place that will hopefully cease to exist soon. | ||
* | ||
* It is a workaround for: | ||
* Flow does not validate any of these imports. This is a workaround for: | ||
* https://github.com/facebook/flow/issues/1448 | ||
*/ | ||
import ExtendableError from 'es6-error'; | ||
import promisify from 'es6-promisify'; | ||
import signAddon from 'sign-addon'; | ||
import {createInstance as createLinter} from 'addons-linter'; | ||
|
||
export {promisify, ExtendableError, signAddon}; | ||
export {promisify, ExtendableError, signAddon, createLinter}; |
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,102 @@ | ||
/* @flow */ | ||
import {it, describe} from 'mocha'; | ||
import {assert} from 'chai'; | ||
import sinon from 'sinon'; | ||
|
||
import defaultLintCommand from '../../src/cmd/lint'; | ||
import {makeSureItFails} from '../helpers'; | ||
|
||
describe('lint', () => { | ||
|
||
function setUp({createLinter} = {}) { | ||
const lintResult = '<lint.run() result placeholder>'; | ||
const runLinter = sinon.spy(() => Promise.resolve(lintResult)); | ||
if (!createLinter) { | ||
createLinter = sinon.spy(() => { | ||
return {run: runLinter}; | ||
}); | ||
} | ||
return { | ||
lintResult, | ||
createLinter, | ||
runLinter, | ||
lint: ({...args}) => { | ||
return defaultLintCommand(args, {createLinter}); | ||
}, | ||
}; | ||
} | ||
|
||
it('creates and runs a linter', () => { | ||
const {lint, createLinter, runLinter, lintResult} = setUp(); | ||
return lint().then((actualLintResult) => { | ||
assert.equal(actualLintResult, lintResult); | ||
assert.equal(createLinter.called, true); | ||
assert.equal(runLinter.called, true); | ||
}); | ||
}); | ||
|
||
it('fails when the linter fails', () => { | ||
const createLinter = () => { | ||
return { | ||
run: () => Promise.reject(new Error('some error from the linter')), | ||
}; | ||
}; | ||
const {lint} = setUp({createLinter}); | ||
return lint().then(makeSureItFails(), (error) => { | ||
assert.match(error.message, /error from the linter/); | ||
}); | ||
}); | ||
|
||
it('runs as a binary', () => { | ||
const {lint, createLinter} = setUp(); | ||
return lint().then(() => { | ||
const args = createLinter.firstCall.args[0]; | ||
assert.equal(args.runAsBinary, true); | ||
}); | ||
}); | ||
|
||
it('passes sourceDir to the linter', () => { | ||
const {lint, createLinter} = setUp(); | ||
return lint({sourceDir: '/some/path'}).then(() => { | ||
const config = createLinter.firstCall.args[0].config; | ||
assert.equal(config._[0], '/some/path'); | ||
}); | ||
}); | ||
|
||
it('configures the linter when verbose', () => { | ||
const {lint, createLinter} = setUp(); | ||
return lint({verbose: true}).then(() => { | ||
const config = createLinter.firstCall.args[0].config; | ||
assert.equal(config.logLevel, 'debug'); | ||
assert.equal(config.stack, true); | ||
}); | ||
}); | ||
|
||
it('configures the linter when not verbose', () => { | ||
const {lint, createLinter} = setUp(); | ||
return lint({verbose: false}).then(() => { | ||
const config = createLinter.firstCall.args[0].config; | ||
assert.equal(config.logLevel, 'fatal'); | ||
assert.equal(config.stack, false); | ||
}); | ||
}); | ||
|
||
it('passes through linter configuration', () => { | ||
const {lint, createLinter} = setUp(); | ||
return lint({ | ||
pretty: 'pretty flag', | ||
metadata: 'metadata flag', | ||
output: 'output value', | ||
boring: 'boring flag', | ||
selfHosted: 'self-hosted flag', | ||
}).then(() => { | ||
const config = createLinter.firstCall.args[0].config; | ||
assert.equal(config.pretty, 'pretty flag'); | ||
assert.equal(config.metadata, 'metadata flag'); | ||
assert.equal(config.output, 'output value'); | ||
assert.equal(config.boring, 'boring flag'); | ||
assert.equal(config.selfHosted, 'self-hosted flag'); | ||
}); | ||
}); | ||
|
||
}); |