diff --git a/src/plugins/codeStyle/index.spec.ts b/src/plugins/codeStyle/index.spec.ts index 062a5d0..57864c4 100644 --- a/src/plugins/codeStyle/index.spec.ts +++ b/src/plugins/codeStyle/index.spec.ts @@ -595,7 +595,7 @@ describe('codeStyle', () => { `19:LINT3014:Add comma after the expression`, `20:LINT3014:Add comma after the expression`, `21:LINT3014:Add comma after the expression`, - `27:LINT3014:Add comma after the expression` + `31:LINT3013:Remove optional comma` ]; expect(actual).deep.equal(expected); }); diff --git a/src/plugins/codeStyle/index.ts b/src/plugins/codeStyle/index.ts index e229906..cec73ad 100644 --- a/src/plugins/codeStyle/index.ts +++ b/src/plugins/codeStyle/index.ts @@ -167,10 +167,14 @@ export default class CodeStyle { validateAAStyle(aa: AALiteralExpression, aaCommaStyle: RuleAAComma, diagnostics: (Omit)[]) { const indexes = collectWrappingAAMembersIndexes(aa); const last = indexes.length - 1; + const isSingleLine = (aa: AALiteralExpression): boolean => { + return aa.open.range.start.line === aa.close.range.end.line; + }; + indexes.forEach((index, i) => { const member = aa.elements[index] as AAMemberExpression; const hasComma = !!member.commaToken; - if (aaCommaStyle === 'never' || (i === last && aaCommaStyle === 'no-dangling')) { + if (aaCommaStyle === 'never' || (i === last && ((aaCommaStyle === 'no-dangling') || isSingleLine(aa)))) { if (hasComma) { diagnostics.push(messages.removeAAComma(member.commaToken.range)); } diff --git a/test/project1/source/aa-style-always.brs b/test/project1/source/aa-style-always.brs index 0725ffb..2249963 100644 --- a/test/project1/source/aa-style-always.brs +++ b/test/project1/source/aa-style-always.brs @@ -24,9 +24,9 @@ sub syle3() end sub sub style4() - a = { a1: 1, a2: 2, a3: 3, } + a = { a1: 1, a2: 2, a3: 3 } end sub sub style5() - a = { a1: 1, a2: 2, a3: 3, } + a = { a1: 1, a2: 2, a3: 3 } end sub