-
Notifications
You must be signed in to change notification settings - Fork 48
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
#460: Ignore enclosing backticks from identifier analysis. #477
Conversation
Rules: * [lower-camel-case] * [constant-naming] * [constant-k-prefix]
…he opening backtick
51fb395
to
d9ec09b
Compare
Location location = ListenerUtil.getContextStartLocation(ctx); | ||
// Ensure that the violation column number reports the character after the opening backtick. | ||
if (CharFormatUtil.isEnclosedInBackticks(ctx.getText())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could create a function that returns the first character of an identifier and accounts for the escaped case (since we're doing this in a couple of places).
assertTrue(CharFormatUtil.unescapeIdentifier("").isEmpty()); | ||
assertTrue(CharFormatUtil.unescapeIdentifier("`s`").equals("s")); | ||
assertTrue(CharFormatUtil.unescapeIdentifier("`self`").equals("self")); | ||
assertFalse(CharFormatUtil.unescapeIdentifier("`self").equals("self")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertFalse
is kind of weird here (it's like saying we expect that it should be anything but self
). Can we change this to assertEqual
(and the following assertFalse
(s) as well)?
// Backtick(s) are not part of the identifier | ||
assertTrue(CharFormatUtil.unescapeIdentifier("``").isEmpty()); | ||
assertTrue(CharFormatUtil.unescapeIdentifier("").isEmpty()); | ||
assertTrue(CharFormatUtil.unescapeIdentifier("`s`").equals("s")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use assertEquals(CharFormatUtil.unescapeIdentifier("`s`"), "s")
instead (this applies to everything that follows)
@@ -49,9 +49,18 @@ public void enterUnionStyleEnumCase(SwiftParser.UnionStyleEnumCaseContext ctx) { | |||
} | |||
|
|||
private void verifyLowerCamelCase(String constructType, ParserRuleContext ctx) { | |||
String constructName = ctx.getText(); | |||
verifyLowerCamelCase(constructType, ctx, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you not escape function and enum names?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! 😄
* @param ctx the context | ||
* @return the start location of the provided context's string | ||
*/ | ||
public static Location getIdentifierStartLocation(ParserRuleContext ctx) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe make the parameter type 'IdentifierContext' for clearer semantics
Based on the work done in #461 by @kober32 last year.
Fixes #460.