Skip to content

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

Merged
adityatrivedi merged 7 commits intomasterfrom
at-460-ignoring-backticks
Mar 25, 2017
Merged

#460: Ignore enclosing backticks from identifier analysis.#477
adityatrivedi merged 7 commits intomasterfrom
at-460-ignoring-backticks

Conversation

@adityatrivedi
Copy link
Copy Markdown
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
@adityatrivedi adityatrivedi requested a review from a4sriniv March 6, 2017 08:59
@adityatrivedi adityatrivedi force-pushed the at-460-ignoring-backticks branch from 51fb395 to d9ec09b Compare March 6, 2017 09:02
String constantName = CharFormatUtil.unescapeIdentifier(ctx.getText());
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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)


private void verifyLowerCamelCase(String constructType, ParserRuleContext ctx) {
String constructName = ctx.getText();
verifyLowerCamelCase(constructType, ctx, false);
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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