-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Issues/5530 use consistent naming #5698
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
Closed
chrischild
wants to merge
21
commits into
Azure:master
from
chrischild:issues/5530-use-consistent-naming
Closed
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
3442b44
New Checkstyle for disallowed words. (#5530)
7e6a5ee
New Checkstyle for disallowed words. (#5530)
847a869
Merge branch 'master' of https://github.com/Azure/azure-sdk-for-java …
4f00cb0
New Checkstyle for disallowed words. (#5530)
19a4f7e
New Checkstyle for disallowed words. (#5530)
3ae6a99
New Checkstyle for disallowed words. (#5530)
6c98480
Initial change for changeLog and readme (#5658)
sima-zhu 30ac105
Adds support for proxies in Event Hubs (#5621)
conniey 33bedb2
Fixes possible null pointer deference spotbugs issue on Key Vault cli…
samvaity a72edc8
Move the datalake error models to implementation model (#5695)
sima-zhu ae62758
Readme update for sasToken API in builder (#5697)
sima-zhu e0a4a3e
Remove SAS Generation Methods from Clients (#5617)
alzimmermsft 5cc9153
azure-core JavaDocs and code snippet clean-up (#5653)
conniey ce3e131
Storage InputStream and OutputStream (#5455)
sima-zhu d7b3d91
Renaming classes and methods as per naming guidelines (#5691)
srnagar 950bc61
Update README and CHANGELOG for Event Hubs (#5700)
srnagar baa2dab
Add remove to HttpHeaders (#5704)
alzimmermsft 9a53f37
Merge branch 'master' of https://github.com/Azure/azure-sdk-for-java …
518f8f9
Merge branch 'issues/5530-use-consistent-naming' of https://github.co…
531abcb
New Checkstyle for disallowed words. (5530)
1b49e66
Refactored New Checkstyle
chrischild File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
129 changes: 129 additions & 0 deletions
129
...quality-reports/src/main/java/com/azure/tools/checkstyle/checks/DisallowedWordsCheck.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.azure.tools.checkstyle.checks; | ||
|
|
||
| import com.puppycrawl.tools.checkstyle.api.AbstractCheck; | ||
| import com.puppycrawl.tools.checkstyle.api.DetailAST; | ||
| import com.puppycrawl.tools.checkstyle.api.TokenTypes; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.HashSet; | ||
| import java.util.Set; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class DisallowedWordsCheck extends AbstractCheck { | ||
| private Set<String> disallowedWords = new HashSet<>(Arrays.asList()); | ||
| private String errorMessage = "%s, All Public API Classes, Fields and Methods should follow " + | ||
|
chrischild marked this conversation as resolved.
Outdated
|
||
| "Camelcase standards for the following words: %s."; | ||
|
|
||
| /** | ||
| * Adds words that Classes, Methods and Variables that should follow Camelcasing standards | ||
| * @param disallowedWords words that should follow normal Camelcasing standards | ||
| */ | ||
| public final void setDisallowedWords(String... disallowedWords) { | ||
| if (disallowedWords != null) { | ||
| Collections.addAll(this.disallowedWords, disallowedWords); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public int[] getDefaultTokens() { | ||
| return getRequiredTokens(); | ||
| } | ||
|
|
||
| @Override | ||
| public int[] getAcceptableTokens() { | ||
| return getRequiredTokens(); | ||
| } | ||
|
|
||
| @Override | ||
| public int[] getRequiredTokens() { | ||
| return new int[] {TokenTypes.CLASS_DEF, | ||
| TokenTypes.VARIABLE_DEF, | ||
| TokenTypes.METHOD_DEF}; | ||
| } | ||
|
|
||
| @Override | ||
| public void visitToken(DetailAST token) { | ||
| switch (token.getType()) { | ||
| case TokenTypes.CLASS_DEF: | ||
| case TokenTypes.METHOD_DEF: | ||
| if (isPublicAPI(token)) { | ||
|
chrischild marked this conversation as resolved.
Outdated
|
||
| String tokenName = token.findFirstToken(TokenTypes.IDENT).getText(); | ||
| boolean found = getDisallowedWords(tokenName); | ||
|
chrischild marked this conversation as resolved.
Outdated
|
||
| if (found) { | ||
| log(token, String.format(errorMessage, tokenName, this.disallowedWords.stream().collect(Collectors.joining(", ", "", "")))); | ||
| } | ||
| } | ||
| break; | ||
| default: | ||
| // Checkstyle complains if there's no default block in switch | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Should we check member with given modifiers. | ||
| * | ||
| * @param token | ||
| * modifiers of member to check. | ||
| * @return true if we should check such member. | ||
| */ | ||
| private boolean isPublicAPI(DetailAST token) { | ||
| final DetailAST modifiersAST = | ||
| token.findFirstToken(TokenTypes.MODIFIERS); | ||
| final boolean isStatic = modifiersAST.findFirstToken(TokenTypes.LITERAL_STATIC) != null; | ||
| final boolean isPublic = modifiersAST | ||
|
chrischild marked this conversation as resolved.
|
||
| .findFirstToken(TokenTypes.LITERAL_PUBLIC) != null; | ||
| final boolean isProtected = modifiersAST.findFirstToken(TokenTypes.LITERAL_PROTECTED) != null; | ||
| return (isPublic || isProtected) && !isStatic; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the disallowed abbreviation contained in given String. | ||
| * @param tokenName | ||
| * the given String. | ||
| * @return the disallowed abbreviation contained in given String as a | ||
| * separate String. | ||
| */ | ||
| private boolean getDisallowedWords(String tokenName) { | ||
| boolean result = false; | ||
| for (String disallowedWord : disallowedWords) { | ||
| if (tokenName.contains(disallowedWord)) { | ||
| result = true; | ||
| break; | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| /** | ||
| * Get Abbreviation if it is illegal, where {@code beginIndex} and {@code endIndex} are | ||
| * inclusive indexes of a sequence of consecutive upper-case characters. | ||
| * @param tokenName name | ||
| * @param beginIndex begin index | ||
| * @param endIndex end index | ||
| * @return the abbreviation if it is bigger than required and not in the | ||
| * ignore list, otherwise {@code null} | ||
| */ | ||
| private String getAbbreviationIfIllegal(String tokenName, int beginIndex, int endIndex) { | ||
| String result = null; | ||
| final String abbr = getAbbreviation(tokenName, beginIndex, endIndex); | ||
| if (disallowedWords.contains(abbr)) { | ||
| result = abbr; | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| private static String getAbbreviation(String tokenName, int beginIndex, int endIndex) { | ||
| String result; | ||
| if (endIndex == tokenName.length() - 1) { | ||
| result = tokenName.substring(beginIndex); | ||
| } else { | ||
| result = tokenName.substring(beginIndex, endIndex); | ||
| } | ||
| return result; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...ty-reports/src/test/java/com/azure/tools/checkstyle/checks/DisallowedWordsCheckTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package com.azure.tools.checkstyle.checks; | ||
|
chrischild marked this conversation as resolved.
|
||
|
|
||
| import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport; | ||
| import com.puppycrawl.tools.checkstyle.Checker; | ||
| import com.puppycrawl.tools.checkstyle.DefaultConfiguration; | ||
| import com.puppycrawl.tools.checkstyle.api.CheckstyleException; | ||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
|
|
||
| public class DisallowedWordsCheckTests extends AbstractModuleTestSupport { | ||
| private static final String DISALLOWED_WORD_ERROR_MESSAGE = "%s, All Public API Classes, Fields and Methods should follow" + | ||
| " Camelcase standards for the following words: XML, HTTP, URL."; | ||
|
|
||
| private Checker checker; | ||
|
|
||
| @Before | ||
| public void prepare() throws Exception { | ||
| checker = prepareCheckStyleChecker(); | ||
| checker.addListener(this.getBriefUtLogger()); | ||
| } | ||
|
|
||
| @After | ||
| public void cleanup() { | ||
| checker.destroy(); | ||
| } | ||
|
|
||
| @Override | ||
| protected String getPackageLocation() { | ||
| return "com/azure/tools/checkstyle/checks/DisallowedWordsChecks"; | ||
| } | ||
|
|
||
| @Test | ||
| public void disallowedWordsTestData() throws Exception { | ||
| String[] expected = { | ||
| expectedErrorMessage(3, 5, String.format(DISALLOWED_WORD_ERROR_MESSAGE, "errorHTTPMethod")), | ||
| expectedErrorMessage(9, 5, String.format(DISALLOWED_WORD_ERROR_MESSAGE, "invalidXMLMethod")) | ||
| }; | ||
| verify(checker, getPath("DisallowedWordsTestData.java"), expected); | ||
| } | ||
|
|
||
| private String expectedErrorMessage(int line, int column, String errorMessage) { | ||
| return String.format("%d:%d: %s", line, column, errorMessage); | ||
| } | ||
|
|
||
| private Checker prepareCheckStyleChecker() throws CheckstyleException { | ||
| Checker checker = new Checker(); | ||
| checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader()); | ||
| checker.configure(prepareConfiguration()); | ||
| return checker; | ||
| } | ||
|
|
||
| private DefaultConfiguration prepareConfiguration() { | ||
| DefaultConfiguration checks = new DefaultConfiguration("Checks"); | ||
| DefaultConfiguration treeWalker = new DefaultConfiguration("TreeWalker"); | ||
| DefaultConfiguration camelCaseCheck = new DefaultConfiguration(DisallowedWordsCheck.class.getCanonicalName()); | ||
| camelCaseCheck.addAttribute("disallowedWords", "URL, HTTP, XML"); | ||
| checks.addChild(treeWalker); | ||
| treeWalker.addChild(camelCaseCheck); | ||
| return checks; | ||
| } | ||
| } | ||
12 changes: 12 additions & 0 deletions
12
...rces/com/azure/tools/checkstyle/checks/DisallowedWordsChecks/DisallowedWordsTestData.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| @JacksonXmlRootElement(localName = "File-SetHTTPHeaders-Headers") | ||
| public class CamelCaseTestData { | ||
| public void errorHTTPMethod() { throw new RuntimeException("Error Messages."); } | ||
|
|
||
| public void validHttpMethod() { throw new RuntimeException("Error Messages."); } | ||
|
|
||
| public static void itIsAURLError() { throw new RuntimeException("Error Messages."); } | ||
|
|
||
| protected void invalidXMLMethod() { throw new RuntimeException("Error Messages."); } | ||
|
|
||
| private void shouldNotSearch() { throw new RuntimeException("Error Messages."); } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.