-
Notifications
You must be signed in to change notification settings - Fork 37
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
Ilyas RIAH #19
Open
iIyas-RIAH
wants to merge
4
commits into
BelmoMusta:develop
Choose a base branch
from
iIyas-RIAH:develop
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Ilyas RIAH #19
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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
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,47 @@ | ||
package com.ensao.gi5.lint.rules; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import com.ensao.gi5.lint.constantes.Constantes; | ||
import com.ensao.gi5.lint.rules.violations.Violation; | ||
import com.ensao.gi5.lint.visitor.IfElseVisitor; | ||
import com.ensao.gi5.lint.wrapper.CompilationUnitWrapper; | ||
import com.ensao.gi5.lint.wrapper.StmtWrapper; | ||
|
||
public class BoolExpRule extends Rule{ | ||
|
||
public BoolExpRule() { | ||
super(Constantes.LINT_REG_006, Level.HIGHEST); | ||
} | ||
|
||
@Override | ||
public void apply(CompilationUnitWrapper compilationUnit) { | ||
List<StmtWrapper> BoolExpWrappers = new ArrayList<>(); | ||
compilationUnit.accept(new IfElseVisitor(), BoolExpWrappers); | ||
|
||
for (StmtWrapper BoolExpWrapper : BoolExpWrappers) { | ||
Matcher matcher = Pattern | ||
.compile("(([\\\\w\\\\d\\\\s.])+(==|!=|<|>|>=|<=)[\\\\w\\\\d\\\\s.]+([&\\\\|]{2})?)+") | ||
.matcher(BoolExpWrapper.getStatement().toString()); | ||
|
||
if (!matcher.find()) { | ||
final Violation violation = new Violation(); | ||
violation.setDescription("Boolean expressions must have no more than 2 operands"); | ||
violation.setFileName(compilationUnit.getFileName()); | ||
violation.setLine(BoolExpWrapper.getLigne()); | ||
violation.setRuleId(Constantes.LINT_REG_006); | ||
violation.setLevel(Level.HIGHEST); | ||
addViolation(violation); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isActive() { | ||
return true; | ||
} | ||
|
||
} |
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,81 @@ | ||
package com.ensao.gi5.lint.rules; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.ensao.gi5.lint.constantes.Constantes; | ||
import com.ensao.gi5.lint.rules.violations.Violation; | ||
import com.ensao.gi5.lint.visitor.ClassVisitor; | ||
import com.ensao.gi5.lint.wrapper.CompilationUnitWrapper; | ||
import com.ensao.gi5.lint.wrapper.classe.ClassWrapper; | ||
import com.ensao.gi5.lint.wrapper.classe.Construct; | ||
import com.ensao.gi5.lint.wrapper.classe.Methode; | ||
|
||
public class ClassRule extends Rule { | ||
|
||
public ClassRule() { | ||
super(Constantes.LINT_REG_002, Level.HIGHEST); | ||
} | ||
|
||
@Override | ||
public void apply(CompilationUnitWrapper compilationUnit) { | ||
|
||
List<ClassWrapper> classes = new ArrayList<>(); | ||
compilationUnit.accept(new ClassVisitor(), classes); | ||
|
||
for (ClassWrapper classe : classes) { | ||
if (classe.getMethodes().size() > 20) { | ||
final Violation violation = new Violation(); | ||
violation.setDescription("The number of methods must not exceed 20 methods declared per class"); | ||
violation.setFileName(compilationUnit.getFileName()); | ||
violation.setLine(classe.getLigne()); | ||
violation.setRuleId(Constantes.LINT_REG_011); | ||
violation.setLevel(Level.HIGHEST); | ||
violation.setDescription(classe.getName() + " " + classe.getMethodes().size()); | ||
addViolation(violation); | ||
} | ||
|
||
for (Construct construct : classe.getConstructs()) { | ||
if (construct.getParametres().size() > 2) { | ||
final Violation violation = new Violation(); | ||
violation.setDescription("The number of parameters of a constructor must not exceed 2"); | ||
violation.setFileName(compilationUnit.getFileName()); | ||
violation.setLine(classe.getLigne()); | ||
violation.setRuleId(Constantes.LINT_REG_012); | ||
violation.setLevel(Level.HIGHEST); | ||
violation.setDescription(construct.getName() + " " + construct.getParametres().size()); | ||
addViolation(violation); | ||
} | ||
} | ||
|
||
for (Methode methode : classe.getMethodes()) { | ||
if (methode.getLinesCount() > 30) { | ||
final Violation violation = new Violation(); | ||
violation.setDescription("The body of a method must not exceed 30 lines"); | ||
violation.setFileName(compilationUnit.getFileName()); | ||
violation.setLine(methode.getLigne()); | ||
violation.setRuleId(Constantes.LINT_REG_008); | ||
violation.setLevel(Level.HIGHEST); | ||
violation.setDescription(methode.getName() + " in " + classe.getName() + " " + methode.getLinesCount()); | ||
addViolation(violation); | ||
} | ||
if (methode.getParametres().size() > 2) { | ||
final Violation violation = new Violation(); | ||
violation.setDescription("The number of parameters of a method must not exceed 2"); | ||
violation.setFileName(compilationUnit.getFileName()); | ||
violation.setLine(classe.getLigne()); | ||
violation.setRuleId(Constantes.LINT_REG_012); | ||
violation.setLevel(Level.HIGHEST); | ||
violation.setDescription(methode.getName() + " " + methode.getParametres().size()); | ||
addViolation(violation); | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isActive() { | ||
return true; | ||
} | ||
|
||
} |
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,39 @@ | ||
package com.ensao.gi5.lint.rules; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import com.ensao.gi5.lint.constantes.Constantes; | ||
import com.ensao.gi5.lint.rules.violations.Violation; | ||
import com.ensao.gi5.lint.visitor.EnumVisitor; | ||
import com.ensao.gi5.lint.wrapper.CompilationUnitWrapper; | ||
import com.ensao.gi5.lint.wrapper.enumeration.EnumWrapper; | ||
|
||
public class EnumRule extends Rule { | ||
|
||
public EnumRule() { | ||
super(Constantes.LINT_REG_007, Level.LOW); | ||
} | ||
|
||
@Override | ||
public void apply(CompilationUnitWrapper compilationUnit) { | ||
List<EnumWrapper> EnumWrappers = new ArrayList<>(); | ||
compilationUnit.accept(new EnumVisitor(), EnumWrappers); | ||
|
||
EnumWrappers.forEach(enumWrapper -> enumWrapper.getElements().forEach(enumElement -> { | ||
if (!enumElement.getName().matches("[A-Z_]+")) { | ||
final Violation violation = new Violation(); | ||
violation.setDescription("The elements of an enumeration are in uppercase, with _ as separator"); | ||
violation.setFileName(compilationUnit.getFileName()); | ||
violation.setLine(enumElement.getLigne()); | ||
violation.setRuleId(Constantes.LINT_REG_007); | ||
violation.setLevel(Level.LOW); | ||
addViolation(violation); | ||
} | ||
})); | ||
} | ||
|
||
@Override | ||
public boolean isActive() { | ||
return true; | ||
} | ||
} |
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,45 @@ | ||
package com.ensao.gi5.lint.rules; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import com.ensao.gi5.lint.constantes.Constantes; | ||
import com.ensao.gi5.lint.rules.violations.Violation; | ||
import com.ensao.gi5.lint.visitor.IfElseVisitor; | ||
import com.ensao.gi5.lint.wrapper.CompilationUnitWrapper; | ||
import com.ensao.gi5.lint.wrapper.StmtWrapper; | ||
|
||
public class IfElseRule extends Rule{ | ||
|
||
public IfElseRule() { | ||
super(Constantes.LINT_REG_018, Level.LOW); | ||
} | ||
|
||
@Override | ||
public void apply(CompilationUnitWrapper compilationUnit) { | ||
List<StmtWrapper> ifElseWrappers = new ArrayList<>(); | ||
compilationUnit.accept(new IfElseVisitor(),ifElseWrappers); | ||
|
||
for(StmtWrapper ifElseWrapper: ifElseWrappers){ | ||
Matcher matcher = Pattern.compile(".*\\{([\\S\\s]*)\\}").matcher(ifElseWrapper.getStatement().toString()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use visitor pattern |
||
|
||
if(!matcher.find()){ | ||
final Violation violation = new Violation(); | ||
violation.setDescription("if/else clauses must have braces" ); | ||
violation.setFileName(compilationUnit.getFileName()); | ||
violation.setLine(ifElseWrapper.getLigne()); | ||
violation.setRuleId(Constantes.LINT_REG_018); | ||
violation.setLevel(Level.LOW); | ||
addViolation(violation); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isActive() { | ||
return true; | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/com/ensao/gi5/lint/rules/UnusedVariablesRule.java
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,42 @@ | ||
package com.ensao.gi5.lint.rules; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.ensao.gi5.lint.constantes.Constantes; | ||
import com.ensao.gi5.lint.rules.violations.Violation; | ||
import com.ensao.gi5.lint.visitor.UnusedVariablesVisitors; | ||
import com.ensao.gi5.lint.wrapper.CompilationUnitWrapper; | ||
import com.ensao.gi5.lint.wrapper.VariableWrapper; | ||
|
||
public class UnusedVariablesRule extends Rule { | ||
|
||
public UnusedVariablesRule() { | ||
super(Constantes.LINT_REG_016, Level.MEDIUM); | ||
} | ||
|
||
@Override | ||
public void apply(CompilationUnitWrapper compilationUnit) { | ||
List<VariableWrapper> variableWrappers = new ArrayList<>(); | ||
compilationUnit.accept(new UnusedVariablesVisitors(), variableWrappers); | ||
|
||
for(VariableWrapper variableWrapper: variableWrappers){ | ||
|
||
if(variableWrapper.getUsageCount()==1){ | ||
final Violation violation = new Violation(); | ||
violation.setDescription("Unused variables should be deleted"); | ||
violation.setFileName(compilationUnit.getFileName()); | ||
violation.setLine(variableWrapper.getLigne()); | ||
violation.setRuleId(Constantes.LINT_REG_016); | ||
violation.setLevel(Level.MEDIUM); | ||
addViolation(violation); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isActive() { | ||
return true; | ||
} | ||
|
||
} |
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
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
22 changes: 22 additions & 0 deletions
22
src/main/java/com/ensao/gi5/lint/visitor/BoolExpVisitor.java
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,22 @@ | ||
package com.ensao.gi5.lint.visitor; | ||
|
||
import java.util.List; | ||
import java.util.regex.Pattern; | ||
|
||
import com.ensao.gi5.lint.wrapper.StmtWrapper; | ||
import com.github.javaparser.ast.stmt.BlockStmt; | ||
import com.github.javaparser.ast.visitor.VoidVisitorAdapter; | ||
|
||
public class BoolExpVisitor extends VoidVisitorAdapter<List<StmtWrapper>> { | ||
|
||
@Override | ||
public void visit(BlockStmt blockStmt, List<StmtWrapper> arg) { | ||
|
||
blockStmt.getStatements().stream().filter(s -> Pattern.compile("==|!=|<|>|>=|<=") | ||
.matcher(s.toString()).find()).forEach(s -> | ||
arg.add(new StmtWrapper(s)) | ||
); | ||
super.visit(blockStmt, arg); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/com/ensao/gi5/lint/visitor/ClassVisitor.java
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,39 @@ | ||
package com.ensao.gi5.lint.visitor; | ||
|
||
import java.util.List; | ||
|
||
import com.ensao.gi5.lint.util.Utils; | ||
import com.ensao.gi5.lint.wrapper.classe.ClassWrapper; | ||
import com.ensao.gi5.lint.wrapper.classe.Construct; | ||
import com.ensao.gi5.lint.wrapper.classe.Methode; | ||
import com.ensao.gi5.lint.wrapper.classe.Parametre; | ||
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; | ||
import com.github.javaparser.ast.visitor.VoidVisitorAdapter; | ||
|
||
public class ClassVisitor extends VoidVisitorAdapter<List<ClassWrapper>> { | ||
|
||
@Override | ||
public void visit(ClassOrInterfaceDeclaration CID, List<ClassWrapper> arg) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
ClassWrapper classWrapper = new ClassWrapper(CID.getNameAsString(), Utils.getLine(CID.getName())); | ||
|
||
CID.getConstructors().forEach(c -> { | ||
Construct construct = new Construct(c.getNameAsString(), Utils.getLine(c.getName())); | ||
c.getParameters().forEach(param -> { | ||
construct.getParametres().add(new Parametre(param.getNameAsString(), param.getTypeAsString())); | ||
}); | ||
classWrapper.getConstructs().add(construct); | ||
}); | ||
|
||
CID.getMethods().forEach(m -> { | ||
Methode methode = new Methode(m.getNameAsString(), m.getTypeAsString(), m.getAccessSpecifier().asString(), | ||
m.getBegin().map(p -> p.line).orElse(-1)); | ||
|
||
m.getParameters() | ||
.forEach(p -> methode.getParametres().add(new Parametre(p.getNameAsString(), p.getTypeAsString()))); | ||
classWrapper.getMethodes().add(methode); | ||
}); | ||
|
||
arg.add(classWrapper); | ||
super.visit(CID, arg); | ||
} | ||
} |
Oops, something went wrong.
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.
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.
regex expression is too long, maintenance will be hard