-
-
Save mike-solomon/e49714f543a9eac1c6ddca5821195ffb to your computer and use it in GitHub Desktop.
Test file for example no-bacon rule
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
/** | |
* @fileoverview Don't allow bacon in variable names | |
* @author Mike Solomon | |
*/ | |
"use strict"; | |
//------------------------------------------------------------------------------ | |
// Requirements | |
//------------------------------------------------------------------------------ | |
const rule = require("../../../lib/rules/no-bacon"); | |
const RuleTester = require("eslint").RuleTester; | |
//------------------------------------------------------------------------------ | |
// Tests | |
//------------------------------------------------------------------------------ | |
const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } }); | |
ruleTester.run("no-bacon", rule, { | |
valid: [ | |
"console.log('bacon')", | |
"function ba_con() {}", | |
"class b4c0n {}", | |
"const bac = 'hello'", | |
], | |
invalid: [ | |
{ code: 'const bacon = "hello"', errors: [{ messageId: "avoidBacon"}] }, | |
{ code: 'const bacona = "hello"', errors: [{ messageId: "avoidBacon"}] }, | |
{ code: 'console.log(bacon)', errors: [{ messageId: "avoidBacon"}] }, | |
{ code: 'console.log(abacon)', errors: [{ messageId: "avoidBacon"}] }, | |
{ code: 'function bacon() {}', errors: [{ messageId: "avoidBacon"}] }, | |
{ code: 'function validName(bacon) {}', errors: [{ messageId: "avoidBacon"}] }, | |
{ code: 'function baConstructor() {}', errors: [{ messageId: "avoidBacon"}] }, | |
{ code: 'class bacon {}', errors: [{ messageId: "avoidBacon"}] }, | |
{ code: 'class someBaconClass {}', errors: [{ messageId: "avoidBacon"}] }, | |
], | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment