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

#460: Ignore enclosing backticks from identifier analysis. #477

Merged
merged 7 commits into from
Mar 25, 2017

Conversation

adityatrivedi
Copy link
Member

@adityatrivedi adityatrivedi commented Mar 6, 2017

Based on the work done in #461 by @kober32 last year.

Added util function for removing backticks () from variables and constants. Using this function on [constant-naming], [lower-camel-case], and [constant-k-prefix]` rules

Fixes #460.

@adityatrivedi adityatrivedi added this to the Sprint 22 milestone Mar 6, 2017
Location location = ListenerUtil.getContextStartLocation(ctx);
// Ensure that the violation column number reports the character after the opening backtick.
if (CharFormatUtil.isEnclosedInBackticks(ctx.getText())) {
Copy link
Member

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"));
Copy link
Member

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"));
Copy link
Member

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);
Copy link
Member

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?

Copy link
Member

@a4sriniv a4sriniv left a 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) {
Copy link
Member

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

@adityatrivedi adityatrivedi merged commit 62f92e8 into master Mar 25, 2017
@adityatrivedi adityatrivedi deleted the at-460-ignoring-backticks branch March 25, 2017 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ignoring backticks in variable name
3 participants