From 554fc2d90269b78b162894e081483e56006f2e06 Mon Sep 17 00:00:00 2001 From: Umar Bolatov Date: Tue, 30 Aug 2016 07:24:58 -0700 Subject: [PATCH] Obey object-literal-sort-keys rule (#1528) --- src/configs/recommended.ts | 2 +- src/rules/memberOrderingRule.ts | 16 ++++++++-------- test/configurationTests.ts | 6 ++++++ test/ruleLoaderTests.ts | 2 ++ 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/configs/recommended.ts b/src/configs/recommended.ts index 1cb57c718a0..d0195bd59da 100644 --- a/src/configs/recommended.ts +++ b/src/configs/recommended.ts @@ -91,8 +91,8 @@ export const rules = { "switch-default": true, "trailing-comma": [true, { - "singleline": "never", "multiline": "always", + "singleline": "never", }, ], "triple-equals": [true, "allow-null-check"], diff --git a/src/rules/memberOrderingRule.ts b/src/rules/memberOrderingRule.ts index 4b36d5ee36c..614070f4f5b 100644 --- a/src/rules/memberOrderingRule.ts +++ b/src/rules/memberOrderingRule.ts @@ -42,13 +42,10 @@ const PRESET_ORDERS: { [preset: string]: string[] } = { "protected-instance-method", "private-instance-method", ], - "statics-first": [ + "instance-sandwich": [ "public-static-field", - "public-static-method", "protected-static-field", - "protected-static-method", "private-static-field", - "private-static-method", "public-instance-field", "protected-instance-field", "private-instance-field", @@ -56,11 +53,17 @@ const PRESET_ORDERS: { [preset: string]: string[] } = { "public-instance-method", "protected-instance-method", "private-instance-method", + "public-static-method", + "protected-static-method", + "private-static-method", ], - "instance-sandwich": [ + "statics-first": [ "public-static-field", + "public-static-method", "protected-static-field", + "protected-static-method", "private-static-field", + "private-static-method", "public-instance-field", "protected-instance-field", "private-instance-field", @@ -68,9 +71,6 @@ const PRESET_ORDERS: { [preset: string]: string[] } = { "public-instance-method", "protected-instance-method", "private-instance-method", - "public-static-method", - "protected-static-method", - "private-static-method", ], }; /* end new options */ diff --git a/test/configurationTests.ts b/test/configurationTests.ts index d8a39cd0274..9e99caf5433 100644 --- a/test/configurationTests.ts +++ b/test/configurationTests.ts @@ -69,11 +69,13 @@ describe("Configuration", () => { let config = loadConfigurationFromPath("./test/config/tslint-extends-package.json"); assert.isArray(config.rulesDirectory); + /* tslint:disable:object-literal-sort-keys */ assert.deepEqual(config.rules, { "rule-one": true, "rule-two": true, "rule-three": false, }); + /* tslint:enable:object-literal-sort-keys */ }); it("extends with package without customization", () => { @@ -130,12 +132,14 @@ describe("Configuration", () => { assert.lengthOf(config.rulesDirectory, 2); assert.isTrue(fs.existsSync(config.rulesDirectory[0])); assert.isTrue(fs.existsSync(config.rulesDirectory[1])); + /* tslint:disable:object-literal-sort-keys */ assert.deepEqual(config.rules, { "always-fail": false, "rule-one": true, "rule-two": true, "rule-four": true, }); + /* tslint:enable:object-literal-sort-keys */ }); it("extends with array", () => { @@ -153,11 +157,13 @@ describe("Configuration", () => { it("can load .json files with comments", () => { const config = loadConfigurationFromPath("./test/config/tslint-with-comments.json"); + /* tslint:disable:object-literal-sort-keys */ assert.deepEqual(config.rules, { "rule-two": true, "rule-three": "//not a comment", "rule-four": "/*also not a comment*/", }); + /* tslint:enable:object-literal-sort-keys */ }); it("can load .json files with BOM", () => { diff --git a/test/ruleLoaderTests.ts b/test/ruleLoaderTests.ts index ed2738e300b..064cc642f93 100644 --- a/test/ruleLoaderTests.ts +++ b/test/ruleLoaderTests.ts @@ -45,12 +45,14 @@ describe("Rule Loader", () => { }); it("doesn't ignore leading or trailing underscores or dashes", () => { + /* tslint:disable:object-literal-sort-keys */ const invalidConfiguration: {[name: string]: any} = { _indent: 6, forin_: true, "-quotemark": "single", "eofline-": true, }; + /* tslint:enable:object-literal-sort-keys */ assert.throws( () => loadRules(invalidConfiguration, {}, RULES_DIRECTORY),