-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: java practice for naming conventions
- Loading branch information
ryzzaki
committed
Jan 27, 2020
1 parent
3739f52
commit b63c767
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,36 @@ | ||
import { IPractice } from '../IPractice'; | ||
import { PracticeEvaluationResult, PracticeImpact, ProgrammingLanguage } from '../../model'; | ||
import { DxPractice } from '../DxPracticeDecorator'; | ||
import { PracticeContext } from '../../contexts/practice/PracticeContext'; | ||
|
||
@DxPractice({ | ||
id: 'Java.NamingConventions', | ||
name: 'Use Java Naming Conventions', | ||
impact: PracticeImpact.high, | ||
suggestion: 'Java class names should begin capitalized as UpperCamelCase or PascalCase in a regular naming convention.', | ||
reportOnlyOnce: true, | ||
url: 'https://www.oracle.com/technetwork/java/codeconventions-135099.html', | ||
}) | ||
export class JavaNamingConventionsPractice implements IPractice { | ||
async isApplicable(ctx: PracticeContext): Promise<boolean> { | ||
return ctx.projectComponent.language === ProgrammingLanguage.Java; | ||
} | ||
|
||
async evaluate(ctx: PracticeContext): Promise<PracticeEvaluationResult> { | ||
if (!ctx.fileInspector) { | ||
return PracticeEvaluationResult.unknown; | ||
} | ||
|
||
const regexDotJava = new RegExp('.java', 'i'); | ||
const javaFiles = await ctx.fileInspector.scanFor(regexDotJava, '/', { shallow: false }); | ||
javaFiles.forEach((file) => { | ||
if (file.baseName !== file.baseName.replace(/^\w/, (firstChar) => firstChar.toUpperCase())) { | ||
return PracticeEvaluationResult.notPracticing; | ||
} else { | ||
return PracticeEvaluationResult.practicing; | ||
} | ||
}); | ||
|
||
return PracticeEvaluationResult.notPracticing; | ||
} | ||
} |
This file contains 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