Skip to content

Commit

Permalink
Add new aa-comma-style all-except-single-line. (#80)
Browse files Browse the repository at this point in the history
* Add new aa-comma-style all-except-single-line. This option will enforce "always" for multiple line AA but for single line AA it will enforce "no-dangling".

* Switch from adding new style to fixing "always" to not require an optional comma for a single-line AA.

* Fix condition check and linter issues

* Switch to function for late evaluation

* Update the expected aa-style-always.brs results.
  • Loading branch information
justinMBullard authored Oct 28, 2022
1 parent df59095 commit 5d8b75b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/plugins/codeStyle/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
6 changes: 5 additions & 1 deletion src/plugins/codeStyle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,14 @@ export default class CodeStyle {
validateAAStyle(aa: AALiteralExpression, aaCommaStyle: RuleAAComma, diagnostics: (Omit<BsDiagnostic, 'file'>)[]) {
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));
}
Expand Down
4 changes: 2 additions & 2 deletions test/project1/source/aa-style-always.brs
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5d8b75b

Please sign in to comment.