Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new aa-comma-style all-except-single-line. #80

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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