UNPKG

eslint-plugin-google-camelcase

Version:
135 lines (128 loc) 4.06 kB
/** * @fileoverview Tests for google-camelcase rule. * @author Gregg Tavares (but it's just a modified version of camelcase by Nicholas C. Zakas) */ //------------------------------------------------------------------------------ // Requirements //------------------------------------------------------------------------------ var linter = require("eslint").linter; var ESLintTester = require("eslint-tester"); var eslintTester = new ESLintTester(linter); //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ eslintTester.addRuleTest("lib/rules/google-camelcase", { valid: [ "firstName = \"Nicholas\"", "FIRST_NAME = \"Nicholas\"", "__myPrivateVariable = \"Patrick\"", "myPrivateVariable_ = \"Patrick\"", "function doSomething(){}", "do_something()", "foo.do_something()", "var foo = bar.baz_boom;", "var foo = bar.baz_boom.something;", "foo.boom_pow.qux = bar.baz_boom.something;", "if (bar.baz_boom) {}", "var obj = { key: foo.bar_baz };", "var arr = [foo.bar_baz];", "[foo.bar_baz]", "var arr = [foo.bar_baz.qux];", "[foo.bar_baz.nesting]", "if (foo.bar_baz === boom.bam_pow) { [foo.baz_boom] }", "var a = opt_test;", "var args = var_args;" ], invalid: [ { code: "first_name = \"Nicholas\"", errors: [ { message: "Identifier 'first_name' is not in camel case.", type: "Identifier" } ] }, { code: "__private_first_name = \"Patrick\"", errors: [ { message: "Identifier '__private_first_name' is not in camel case.", type: "Identifier" } ] }, { code: "function foo_bar(){}", errors: [ { message: "Identifier 'foo_bar' is not in camel case.", type: "Identifier" } ] }, { code: "obj.foo_bar = function(){};", errors: [ { message: "Identifier 'foo_bar' is not in camel case.", type: "Identifier" } ] }, { code: "bar_baz.foo = function(){};", errors: [ { message: "Identifier 'bar_baz' is not in camel case.", type: "Identifier" } ] }, { code: "[foo_bar.baz]", errors: [ { message: "Identifier 'foo_bar' is not in camel case.", type: "Identifier" } ] }, { code: "if (foo.bar_baz === boom.bam_pow) { [foo_bar.baz] }", errors: [ { message: "Identifier 'foo_bar' is not in camel case.", type: "Identifier" } ] }, { code: "foo.bar_baz = boom.bam_pow", errors: [ { message: "Identifier 'bar_baz' is not in camel case.", type: "Identifier" } ] }, { code: "var foo = { bar_baz: boom.bam_pow }", errors: [ { message: "Identifier 'bar_baz' is not in camel case.", type: "Identifier" } ] }, { code: "foo.qux.boom_pow = { bar: boom.bam_pow }", errors: [ { message: "Identifier 'boom_pow' is not in camel case.", type: "Identifier" } ] } ] });