| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324 |
- // Copyright 2016 The Chromium Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style license that can be
- // found in the LICENSE file.
- /* eslint-disable */
- /**
- * @fileoverview Tests for camelcase rule.
- * @author Nicholas C. Zakas
- */
- 'use strict';
- //------------------------------------------------------------------------------
- // Requirements
- //------------------------------------------------------------------------------
- var rule = require("../rules/catapult-camelcase"),
- RuleTester = require("../../node_runner/node_runner/node_modules/eslint/lib/testers/rule-tester");
- //------------------------------------------------------------------------------
- // Tests
- //------------------------------------------------------------------------------
- var ruleTester = new RuleTester();
- ruleTester.run("camelcase", rule, {
- 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] }",
- // These tests are for Catapult-specific exceptions.
- "opt_firstName = \"Nicholas\"",
- "g_firstName = \"Nicholas\"",
- "sizeInBytes_smallerIsBetter = \"Nicholas\"",
- "sizeInBytes_biggerIsBetter = \"Nicholas\"",
- {
- code: "var o = {key: 1}",
- options: [{properties: "always"}]
- },
- {
- code: "var o = {bar_baz: 1}",
- options: [{properties: "never"}]
- },
- {
- code: "obj.a_b = 2;",
- options: [{properties: "never"}]
- },
- {
- code: "var obj = {\n a_a: 1 \n};\n obj.a_b = 2;",
- options: [{properties: "never"}]
- },
- {
- code: "obj.foo_bar = function(){};",
- options: [{properties: "never"}]
- },
- {
- code: "var { category_id: category } = query;",
- parserOptions: { ecmaVersion: 6 }
- },
- {
- code: "var { category_id: category } = query;",
- parserOptions: { ecmaVersion: 6 },
- options: [{properties: "never"}]
- },
- {
- code: "import { camelCased } from \"external module\";",
- parserOptions: { ecmaVersion: 6, sourceType: "module" }
- },
- {
- code: "import { no_camelcased as camelCased } from \"external-module\";",
- parserOptions: { ecmaVersion: 6, sourceType: "module" }
- },
- {
- code: "import { no_camelcased as camelCased, anoterCamelCased } from \"external-module\";",
- parserOptions: { ecmaVersion: 6, sourceType: "module" }
- }
- ],
- 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"
- }
- ]
- },
- {
- code: "var o = {bar_baz: 1}",
- options: [{properties: "always"}],
- errors: [
- {
- message: "Identifier 'bar_baz' is not in camel case.",
- type: "Identifier"
- }
- ]
- },
- {
- code: "obj.a_b = 2;",
- options: [{properties: "always"}],
- errors: [
- {
- message: "Identifier 'a_b' is not in camel case.",
- type: "Identifier"
- }
- ]
- },
- {
- code: "obj.a_b = 2;",
- options: [{properties: "always"}],
- errors: [
- {
- message: "Identifier 'a_b' is not in camel case.",
- type: "Identifier"
- }
- ]
- },
- {
- code: "var { category_id: category_id } = query;",
- parserOptions: { ecmaVersion: 6 },
- errors: [
- {
- message: "Identifier 'category_id' is not in camel case.",
- type: "Identifier"
- }
- ]
- },
- {
- code: "var { category_id } = query;",
- parserOptions: { ecmaVersion: 6 },
- errors: [
- {
- message: "Identifier 'category_id' is not in camel case.",
- type: "Identifier"
- }
- ]
- },
- {
- code: "import no_camelcased from \"external-module\";",
- parserOptions: { ecmaVersion: 6, sourceType: "module" },
- errors: [
- {
- message: "Identifier 'no_camelcased' is not in camel case.",
- type: "Identifier"
- }
- ]
- },
- {
- code: "import * as no_camelcased from \"external-module\";",
- parserOptions: { ecmaVersion: 6, sourceType: "module" },
- errors: [
- {
- message: "Identifier 'no_camelcased' is not in camel case.",
- type: "Identifier"
- }
- ]
- },
- {
- code: "import { no_camelcased } from \"external-module\";",
- parserOptions: { ecmaVersion: 6, sourceType: "module" },
- errors: [
- {
- message: "Identifier 'no_camelcased' is not in camel case.",
- type: "Identifier"
- }
- ]
- },
- {
- code: "import { no_camelcased as no_camel_cased } from \"external module\";",
- parserOptions: { ecmaVersion: 6, sourceType: "module" },
- errors: [
- {
- message: "Identifier 'no_camel_cased' is not in camel case.",
- type: "Identifier"
- }
- ]
- },
- {
- code: "import { camelCased as no_camel_cased } from \"external module\";",
- parserOptions: { ecmaVersion: 6, sourceType: "module" },
- errors: [
- {
- message: "Identifier 'no_camel_cased' is not in camel case.",
- type: "Identifier"
- }
- ]
- },
- {
- code: "import { camelCased, no_camelcased } from \"external-module\";",
- parserOptions: { ecmaVersion: 6, sourceType: "module" },
- errors: [
- {
- message: "Identifier 'no_camelcased' is not in camel case.",
- type: "Identifier"
- }
- ]
- },
- {
- code: "import { no_camelcased as camelCased, another_no_camelcased } from \"external-module\";",
- parserOptions: { ecmaVersion: 6, sourceType: "module" },
- errors: [
- {
- message: "Identifier 'another_no_camelcased' is not in camel case.",
- type: "Identifier"
- }
- ]
- },
- {
- code: "import camelCased, { no_camelcased } from \"external-module\";",
- parserOptions: { ecmaVersion: 6, sourceType: "module" },
- errors: [
- {
- message: "Identifier 'no_camelcased' is not in camel case.",
- type: "Identifier"
- }
- ]
- },
- {
- code: "import no_camelcased, { another_no_camelcased as camelCased } from \"external-module\";",
- parserOptions: { ecmaVersion: 6, sourceType: "module" },
- errors: [
- {
- message: "Identifier 'no_camelcased' is not in camel case.",
- type: "Identifier"
- }
- ]
- }
- ]
- });
|