Created
March 2, 2018 23:03
-
-
Save brentjanderson/76eb1912e8ae9ddcc9884881036010d6 to your computer and use it in GitHub Desktop.
Standards .eslintrc.js
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
module.exports = { | |
env: { | |
es6: true, | |
node: true | |
}, | |
plugins: ["prettier"], | |
extends: ["plugin:prettier/recommended"], | |
parserOptions: { | |
sourceType: "module" | |
}, | |
rules: { | |
"no-console": 0, | |
"no-unused-vars": [2, { argsIgnorePattern: "^_" }], | |
"prettier/prettier": "error" | |
} | |
}; |
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
// Gratefully stolen from https://robots.thoughtbot.com/testing-your-style-with-eslint-and-mocha | |
// For testing with Jest | |
const glob = require("glob"); | |
const { CLIEngine } = require("eslint"); | |
const paths = glob.sync("./+(src|__tests__)/**/*.js"); | |
const engine = new CLIEngine({ | |
envs: ["node", "jest"], | |
useEslintrc: true | |
}); | |
const results = engine.executeOnFiles(paths).results; | |
describe("ESLint", function() { | |
results.forEach(result => generateTest(result)); | |
}); | |
function generateTest(result) { | |
const { filePath, messages } = result; | |
it(`validates ${filePath}`, function() { | |
expect(formatMessages(messages)).toBe(`\n`); | |
}); | |
} | |
function formatMessages(messages) { | |
const errors = messages.map(message => { | |
return `${message.line}:${message.column} ${message.message.slice( | |
0, | |
-1 | |
)} - ${message.ruleId}\n`; | |
}); | |
return `\n${errors.join("")}`; | |
} |
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
// Gratefully stolen from https://robots.thoughtbot.com/testing-your-style-with-eslint-and-mocha | |
// For testing with Mocha | |
const glob = require("glob"); | |
const { CLIEngine } = require("eslint"); | |
const { assert } = require("chai"); | |
const paths = glob.sync("./+(src|test)/**/*.js"); | |
const engine = new CLIEngine({ | |
envs: ["node", "mocha"], | |
useEslintrc: true | |
}); | |
const results = engine.executeOnFiles(paths).results; | |
describe("ESLint", function() { | |
results.forEach(result => generateTest(result)); | |
}); | |
function generateTest(result) { | |
const { filePath, messages } = result; | |
it(`validates ${filePath}`, function() { | |
if (messages.length > 0) { | |
assert.fail(false, true, formatMessages(messages)); | |
} | |
}); | |
} | |
function formatMessages(messages) { | |
const errors = messages.map(message => { | |
return `${message.line}:${message.column} ${message.message.slice( | |
0, | |
-1 | |
)} - ${message.ruleId}\n`; | |
}); | |
return `\n${errors.join("")}`; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment