@@ -29,13 +29,15 @@ import * as Lint from "../index";
2929
3030import { codeExamples } from "./code-examples/objectLiteralSortKeys.examples" ;
3131
32+ const OPTION_IGNORE_BLANK_LINES = "ignore-blank-lines" ;
3233const OPTION_IGNORE_CASE = "ignore-case" ;
3334const OPTION_LOCALE_COMPARE = "locale-compare" ;
3435const OPTION_MATCH_DECLARATION_ORDER = "match-declaration-order" ;
3536const OPTION_MATCH_DECLARATION_ORDER_ONLY = "match-declaration-order-only" ;
3637const OPTION_SHORTHAND_FIRST = "shorthand-first" ;
3738
3839interface Options {
40+ ignoreBlankLines : boolean ;
3941 ignoreCase : boolean ;
4042 localeCompare : boolean ;
4143 matchDeclarationOrder : boolean ;
@@ -52,12 +54,14 @@ export class Rule extends Lint.Rules.OptionallyTypedRule {
5254
5355 When using the default alphabetical ordering, additional blank lines may be used to group
5456 object properties together while keeping the elements within each group in alphabetical order.
57+ To opt out of this use ${ OPTION_IGNORE_BLANK_LINES } option.
5558 ` ,
5659 rationale : "Useful in preventing merge conflicts" ,
5760 optionsDescription : Lint . Utils . dedent `
5861 By default, this rule checks that keys are in alphabetical order.
5962 The following may optionally be passed:
6063
64+ * \`${ OPTION_IGNORE_BLANK_LINES } \` will enforce alphabetical ordering regardless of blank lines between each key-value pair.
6165 * \`${ OPTION_IGNORE_CASE } \` will compare keys in a case insensitive way.
6266 * \`${ OPTION_LOCALE_COMPARE } \` will compare keys using the expected sort order of special characters, such as accents.
6367 * \`${ OPTION_MATCH_DECLARATION_ORDER } \` will prefer to use the key ordering of the contextual type of the object literal, as in:
@@ -83,6 +87,7 @@ export class Rule extends Lint.Rules.OptionallyTypedRule {
8387 options : {
8488 type : "string" ,
8589 enum : [
90+ OPTION_IGNORE_BLANK_LINES ,
8691 OPTION_IGNORE_CASE ,
8792 OPTION_LOCALE_COMPARE ,
8893 OPTION_MATCH_DECLARATION_ORDER ,
@@ -94,6 +99,7 @@ export class Rule extends Lint.Rules.OptionallyTypedRule {
9499 true ,
95100 [
96101 true ,
102+ OPTION_IGNORE_BLANK_LINES ,
97103 OPTION_IGNORE_CASE ,
98104 OPTION_LOCALE_COMPARE ,
99105 OPTION_MATCH_DECLARATION_ORDER ,
@@ -162,6 +168,7 @@ export class Rule extends Lint.Rules.OptionallyTypedRule {
162168
163169function parseOptions ( ruleArguments : any [ ] ) : Options {
164170 return {
171+ ignoreBlankLines : has ( OPTION_IGNORE_BLANK_LINES ) ,
165172 ignoreCase : has ( OPTION_IGNORE_CASE ) ,
166173 localeCompare : has ( OPTION_LOCALE_COMPARE ) ,
167174 matchDeclarationOrder : has ( OPTION_MATCH_DECLARATION_ORDER ) ,
@@ -178,6 +185,7 @@ function walk(ctx: Lint.WalkContext<Options>, checker?: ts.TypeChecker): void {
178185 const {
179186 sourceFile,
180187 options : {
188+ ignoreBlankLines,
181189 ignoreCase,
182190 localeCompare,
183191 matchDeclarationOrder,
@@ -266,6 +274,14 @@ function walk(ctx: Lint.WalkContext<Options>, checker?: ts.TypeChecker): void {
266274 : localeCompare
267275 ? lastKey . localeCompare ( key ) === 1
268276 : lastKey > key ;
277+
278+ if ( keyOrderDescending && ignoreBlankLines ) {
279+ ctx . addFailureAtNode (
280+ property . name ,
281+ Rule . FAILURE_STRING_ALPHABETICAL ( property . name . text ) ,
282+ ) ;
283+ return ;
284+ }
269285 if ( keyOrderDescending && ! hasBlankLineBefore ( ctx . sourceFile , property ) ) {
270286 ctx . addFailureAtNode (
271287 property . name ,
0 commit comments