SlideShare a Scribd company logo
1 of 37
Download to read offline
Salenda
Let Codenarc check if you

write good code
Greach ‘18
Alberto De Ávila Hernández
A B O U T M E
✴ Software Engineer
✴ Team Lead at Salenda
✴ Groovy & Grails dev
@alberto_deavila
S A L E N D A
S O F T WA R E D E V E L O P M E N T
Turnkey
development
Atlassian
Solution
Partner
Consulting and
support in
software
architecture and
analysis
Application
integration
Evolutionary support
of our own
developments or
inherited ones
@alberto_deavila
G O A L S
Goals
G O A L S
✴ Write better code
✴ Learn good practices
✴ Use only one code style criteria
✴ Fix code errors
✴ Don’t Repeat Yourself
✴ Clean code
@alberto_deavila
✴ What’s Codenarc?
✴ Why should you use Codenarc?
✴ Rules
✴ Config in Grails 3
✴ Custom rules
I N D E X
@alberto_deavila
W H AT ’ S C O D E N A R C ?
What’s Codenarc?
✴ Static code analysis tool for Groovy
✴ Similar to PMD or Checkstyle
✴ Opensource
✴ Check coding standards and best practices
✴ Flexible: rules, rulesets and custom rules
✴ Generates an HTML or XML report
W H AT ’ S C O D E N A R C ?
@alberto_deavila
✴ Analyzes:
✴ Defects
✴ Bad practices
✴ Inconsistencies
✴ Style issues
✴ …
W H AT ’ S C O D E N A R C ?
@alberto_deavila
W H Y S H O U L D Y O U U S E C O D E N A R C ?
Why should you use Codenarc?
W H Y S H O U L D I U S E C O D E N A R C ?
@alberto_deavila
✴ In a projects works many programmers
✴ Each person has different style programming
✴ Not all best practices are known
✴ Programmers need tools to check its work
✴ The team can define the rules to apply
✴ Improve your project in many ways
R U L E S
Rules
R U L E S
@alberto_deavila
What’s a rule?
R U L E S
@alberto_deavila
A function that looks at our code to check if
it meets some conditions
R U L E S
@alberto_deavila
What’s a ruleset?
R U L E S
@alberto_deavila
A group of rules of the same type
✴ CodeNarc includes 357 rules
✴ Splited in 22 rulesets
✴ You can contribute with new rules: 

https://github.com/CodeNarc/CodeNarc
R U L E S
@alberto_deavila
R U L E S
@alberto_deavila
What kind of rules are defined?
✴ Basic: empty blocks/classes and many others
✴ DRY: repeated data like strings, numbers…
✴ Exceptions: alert about bad uses of exceptions
✴ Formatting: spaces, docs, blank lines…
✴ Grails: domain with service, duplicate
constraints and mapping, mass assignment…
R U L E S
@alberto_deavila
✴ Groovyism: explicit calls, GString map keys
✴ JUnit: ignoreRest, unnecessary fails…
✴ Naming: validate the files and classes names
✴ Size: methods with too many params,
methods too larges…
✴ Unused: unused variables, methods…
R U L E S
@alberto_deavila
✴ Braces
✴ Concurrency
✴ Convention
✴ Design
✴ Enhanced
✴ Generic
R U L E S
@alberto_deavila
✴ Imports
✴ JDBC
✴ Logging
✴ Security
✴ Serialization
✴ Unnecessary
R U L E S
@alberto_deavila
Rules configuration
✴ Common configuration:
✴ enabled = false
✴ applyToClassNames = ‘*Service’
✴ doNotApplyToClassNames = ‘*Spec,*Util’
✴ priority = 1
✴ Some rules can be configured particularly
R U L E S
@alberto_deavila
C O N F I G I N G R A I L S 3
Config in Grails 3
C O N F I G I N G R A I L S 3
@alberto_deavila
✴ Add plugin to build.gradle :
apply plugin: 'codenarc'
codenarc {
toolVersion = '0.27.0'
configFile = file("${rootProject.projectDir}/config/codenarc/
rules.groovy")
reportFormat = 'html'
ignoreFailures = true
}
C O N F I G I N G R A I L S 3
@alberto_deavila
✴ Create the rules file: 









ruleset {
description 'Grails-CodeNarc Project RuleSet'
ruleset('rulesets/basic.xml')
ruleset('rulesets/braces.xml')
ruleset('rulesets/grails.xml')
}
C O N F I G I N G R A I L S 3
@alberto_deavila
✴ Execute $ ./gradlew app:check
✴ Open test report to check violations:
C U S T O M R U L E S
Custom rules
C U S T O M R U L E S
@alberto_deavila
✴ Define the ruleset:
<ruleset xmlns="http://codenarc.org/ruleset/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://codenarc.org/ruleset/1.0 http://
codenarc.org/ruleset-schema.xsd"
xsi:noNamespaceSchemaLocation="http://codenarc.org/ruleset-
schema.xsd">
<description>Extra Grails rules</description>
<rule class='org.codenarc.rule.grails.GrailsTransactionalRule'/>
</ruleset>
C U S T O M R U L E S
@alberto_deavila
✴ Create the rule config:
class GrailsTransactionalRule extends AbstractAstVisitorRule {
int priority = 2
String name = 'GrailsTransactional'
Class astVisitorClass = GrailsTransactionalVisitor
}
C U S T O M R U L E S
@alberto_deavila
✴ Create the rule implementation:
@CompileStatic
class GrailsTransactionalVisitor extends AbstractAstVisitor {
@Override
void visitAnnotations(AnnotatedNode node) {
node.annotations.each { AnnotationNode annotationNode ->
String annotation = annotationNode.classNode.text
if (annotation ==
“org.springframework.transaction.annotation.Transactional”) {
addViolation(node, “Error msg”)
}
}
super.visitAnnotations(node)
}
}
C U S T O M R U L E S
@alberto_deavila
✴ Create a Gradle project with that rule
✴ Some other config needed
✴ More info:
http://guides.grails.org/grails-codenarc/guide/
index.html#writingCustomRule
C O N C L U S I O N S
Conclusions
C O N C L U S I O N S
@alberto_deavila
✴ Easy to configure and use
✴ Show us a lot of information
✴ Customize the rules to apply
✴ Create your own rules
✴ Maintains a unified code style
✴ You should use it
M O R E I N F O
@alberto_deavila
✴ Grails Guide: 

http://guides.grails.org/grails-codenarc/
guide/index.html
✴ Codenarc doc: 

http://codenarc.sourceforge.net/
✴ Codenarc repo: 

https://github.com/CodeNarc/CodeNarc
SalendaThank you!
@alberto_deavila

More Related Content

What's hot

Gear up for Continuous Integration with Salesforce DX, Circle CI and Clayton
Gear up for Continuous Integration with Salesforce DX, Circle CI and ClaytonGear up for Continuous Integration with Salesforce DX, Circle CI and Clayton
Gear up for Continuous Integration with Salesforce DX, Circle CI and ClaytonDaniel Stange
 
一次项目的探险旅程
一次项目的探险旅程一次项目的探险旅程
一次项目的探险旅程Tony Deng
 
Accessibility Testing Tools for Developers - Seattle Code Camp
Accessibility Testing Tools for Developers - Seattle Code CampAccessibility Testing Tools for Developers - Seattle Code Camp
Accessibility Testing Tools for Developers - Seattle Code Campgerardkcohen
 
Build a production ready PWA - LINKIT & KLM Digital Studio Meetup
Build a production ready PWA - LINKIT & KLM Digital Studio MeetupBuild a production ready PWA - LINKIT & KLM Digital Studio Meetup
Build a production ready PWA - LINKIT & KLM Digital Studio MeetupÖnder Ceylan
 
Dumb and smart components + redux (1)
Dumb and smart components + redux (1)Dumb and smart components + redux (1)
Dumb and smart components + redux (1)Brecht Billiet
 
Deep crawl the chaotic landscape of JavaScript
Deep crawl the chaotic landscape of JavaScript Deep crawl the chaotic landscape of JavaScript
Deep crawl the chaotic landscape of JavaScript Onely
 
Agular in a microservices world
Agular in a microservices worldAgular in a microservices world
Agular in a microservices worldBrecht Billiet
 
How to build a scalable content production system.
How to build a scalable content production system.How to build a scalable content production system.
How to build a scalable content production system.Gareth Simpson
 
Sprint Retrospective Anti-Patterns — Hands-on Agile Webinar #10
Sprint Retrospective Anti-Patterns — Hands-on Agile Webinar #10Sprint Retrospective Anti-Patterns — Hands-on Agile Webinar #10
Sprint Retrospective Anti-Patterns — Hands-on Agile Webinar #10Stefan Wolpers
 
Scrum Sprint Anti-Patterns (Hands-on Agile Webinar #7)
Scrum Sprint Anti-Patterns (Hands-on Agile Webinar #7)Scrum Sprint Anti-Patterns (Hands-on Agile Webinar #7)
Scrum Sprint Anti-Patterns (Hands-on Agile Webinar #7)Stefan Wolpers
 
WordPress - Whats going on in the server?
WordPress - Whats going on in the server? WordPress - Whats going on in the server?
WordPress - Whats going on in the server? Herb Miller
 
Solving Complex JavaScript Issues and Leveraging Semantic HTML5
Solving Complex JavaScript Issues and Leveraging Semantic HTML5Solving Complex JavaScript Issues and Leveraging Semantic HTML5
Solving Complex JavaScript Issues and Leveraging Semantic HTML5Hamlet Batista
 
How To Tackle Enterprise Sites - Rachel Costello, Technical SEO, DeepCrawl
How To Tackle Enterprise Sites - Rachel Costello, Technical SEO, DeepCrawlHow To Tackle Enterprise Sites - Rachel Costello, Technical SEO, DeepCrawl
How To Tackle Enterprise Sites - Rachel Costello, Technical SEO, DeepCrawlDeepCrawl
 
Scrum Master Ant-Patterns — (Hands-on Agile Webinar #8)
Scrum Master Ant-Patterns — (Hands-on Agile Webinar #8)Scrum Master Ant-Patterns — (Hands-on Agile Webinar #8)
Scrum Master Ant-Patterns — (Hands-on Agile Webinar #8)Stefan Wolpers
 
Facebook Social Plugins
Facebook Social PluginsFacebook Social Plugins
Facebook Social PluginsAizat Faiz
 

What's hot (18)

Gear up for Continuous Integration with Salesforce DX, Circle CI and Clayton
Gear up for Continuous Integration with Salesforce DX, Circle CI and ClaytonGear up for Continuous Integration with Salesforce DX, Circle CI and Clayton
Gear up for Continuous Integration with Salesforce DX, Circle CI and Clayton
 
一次项目的探险旅程
一次项目的探险旅程一次项目的探险旅程
一次项目的探险旅程
 
Accessibility Testing Tools for Developers - Seattle Code Camp
Accessibility Testing Tools for Developers - Seattle Code CampAccessibility Testing Tools for Developers - Seattle Code Camp
Accessibility Testing Tools for Developers - Seattle Code Camp
 
Build a production ready PWA - LINKIT & KLM Digital Studio Meetup
Build a production ready PWA - LINKIT & KLM Digital Studio MeetupBuild a production ready PWA - LINKIT & KLM Digital Studio Meetup
Build a production ready PWA - LINKIT & KLM Digital Studio Meetup
 
Dumb and smart components + redux (1)
Dumb and smart components + redux (1)Dumb and smart components + redux (1)
Dumb and smart components + redux (1)
 
Deep crawl the chaotic landscape of JavaScript
Deep crawl the chaotic landscape of JavaScript Deep crawl the chaotic landscape of JavaScript
Deep crawl the chaotic landscape of JavaScript
 
Agular in a microservices world
Agular in a microservices worldAgular in a microservices world
Agular in a microservices world
 
Drupal DOMinate
Drupal DOMinateDrupal DOMinate
Drupal DOMinate
 
How to build a scalable content production system.
How to build a scalable content production system.How to build a scalable content production system.
How to build a scalable content production system.
 
Sprint Retrospective Anti-Patterns — Hands-on Agile Webinar #10
Sprint Retrospective Anti-Patterns — Hands-on Agile Webinar #10Sprint Retrospective Anti-Patterns — Hands-on Agile Webinar #10
Sprint Retrospective Anti-Patterns — Hands-on Agile Webinar #10
 
Scrum Sprint Anti-Patterns (Hands-on Agile Webinar #7)
Scrum Sprint Anti-Patterns (Hands-on Agile Webinar #7)Scrum Sprint Anti-Patterns (Hands-on Agile Webinar #7)
Scrum Sprint Anti-Patterns (Hands-on Agile Webinar #7)
 
WordPress - Whats going on in the server?
WordPress - Whats going on in the server? WordPress - Whats going on in the server?
WordPress - Whats going on in the server?
 
aaa
aaaaaa
aaa
 
Solving Complex JavaScript Issues and Leveraging Semantic HTML5
Solving Complex JavaScript Issues and Leveraging Semantic HTML5Solving Complex JavaScript Issues and Leveraging Semantic HTML5
Solving Complex JavaScript Issues and Leveraging Semantic HTML5
 
How To Tackle Enterprise Sites - Rachel Costello, Technical SEO, DeepCrawl
How To Tackle Enterprise Sites - Rachel Costello, Technical SEO, DeepCrawlHow To Tackle Enterprise Sites - Rachel Costello, Technical SEO, DeepCrawl
How To Tackle Enterprise Sites - Rachel Costello, Technical SEO, DeepCrawl
 
Jabber Bot
Jabber BotJabber Bot
Jabber Bot
 
Scrum Master Ant-Patterns — (Hands-on Agile Webinar #8)
Scrum Master Ant-Patterns — (Hands-on Agile Webinar #8)Scrum Master Ant-Patterns — (Hands-on Agile Webinar #8)
Scrum Master Ant-Patterns — (Hands-on Agile Webinar #8)
 
Facebook Social Plugins
Facebook Social PluginsFacebook Social Plugins
Facebook Social Plugins
 

Similar to Let Codenarc check if you write good Groovy code

What's new in visual studio 2013
What's new in visual studio 2013What's new in visual studio 2013
What's new in visual studio 2013Keith Lopez
 
Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functi...
Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functi...Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functi...
Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functi...Alberto De Ávila Hernández
 
Advanced iOS Debbuging (Reloaded)
Advanced iOS Debbuging (Reloaded)Advanced iOS Debbuging (Reloaded)
Advanced iOS Debbuging (Reloaded)Massimo Oliviero
 
DevSecCon Singapore 2018 - Remove developers’ shameful secrets or simply rem...
DevSecCon Singapore 2018 -  Remove developers’ shameful secrets or simply rem...DevSecCon Singapore 2018 -  Remove developers’ shameful secrets or simply rem...
DevSecCon Singapore 2018 - Remove developers’ shameful secrets or simply rem...DevSecCon
 
Supercharging your Python Development Environment with VS Code and Dev Contai...
Supercharging your Python Development Environment with VS Code and Dev Contai...Supercharging your Python Development Environment with VS Code and Dev Contai...
Supercharging your Python Development Environment with VS Code and Dev Contai...Dawn Wages
 
Coder Presentation
Coder  PresentationCoder  Presentation
Coder PresentationDoug Green
 
DevSecCon SG 2018 Fabian Presentation Slides
DevSecCon SG 2018 Fabian Presentation SlidesDevSecCon SG 2018 Fabian Presentation Slides
DevSecCon SG 2018 Fabian Presentation SlidesFab L
 
Asynchronous single page applications without a line of HTML or Javascript, o...
Asynchronous single page applications without a line of HTML or Javascript, o...Asynchronous single page applications without a line of HTML or Javascript, o...
Asynchronous single page applications without a line of HTML or Javascript, o...Robert Schadek
 
Domain Driven Design Tactical Patterns
Domain Driven Design Tactical PatternsDomain Driven Design Tactical Patterns
Domain Driven Design Tactical PatternsRobert Alexe
 
IDE and Toolset For Magento Development
IDE and Toolset For Magento DevelopmentIDE and Toolset For Magento Development
IDE and Toolset For Magento DevelopmentAbid Malik
 
Tahoe Dreamin 2018: It simply works... until it breaks!
Tahoe Dreamin 2018: It simply works... until it breaks!Tahoe Dreamin 2018: It simply works... until it breaks!
Tahoe Dreamin 2018: It simply works... until it breaks!Daniel Stange
 
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLEAN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLEGavin Pickin
 
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE - CFObjective() 2017
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE - CFObjective() 2017AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE - CFObjective() 2017
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE - CFObjective() 2017Ortus Solutions, Corp
 
Big code refactoring with agility
Big code refactoring with agilityBig code refactoring with agility
Big code refactoring with agilityLuca Merolla
 

Similar to Let Codenarc check if you write good Groovy code (20)

What's new in visual studio 2013
What's new in visual studio 2013What's new in visual studio 2013
What's new in visual studio 2013
 
Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functi...
Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functi...Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functi...
Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functi...
 
Advanced iOS Debbuging (Reloaded)
Advanced iOS Debbuging (Reloaded)Advanced iOS Debbuging (Reloaded)
Advanced iOS Debbuging (Reloaded)
 
Intro. to Git and Github
Intro. to Git and GithubIntro. to Git and Github
Intro. to Git and Github
 
DevSecCon Singapore 2018 - Remove developers’ shameful secrets or simply rem...
DevSecCon Singapore 2018 -  Remove developers’ shameful secrets or simply rem...DevSecCon Singapore 2018 -  Remove developers’ shameful secrets or simply rem...
DevSecCon Singapore 2018 - Remove developers’ shameful secrets or simply rem...
 
Supercharging your Python Development Environment with VS Code and Dev Contai...
Supercharging your Python Development Environment with VS Code and Dev Contai...Supercharging your Python Development Environment with VS Code and Dev Contai...
Supercharging your Python Development Environment with VS Code and Dev Contai...
 
Coder Presentation
Coder  PresentationCoder  Presentation
Coder Presentation
 
Graalvm with Groovy and Kotlin - Greach 2019
Graalvm with Groovy and Kotlin - Greach 2019Graalvm with Groovy and Kotlin - Greach 2019
Graalvm with Groovy and Kotlin - Greach 2019
 
DevSecCon SG 2018 Fabian Presentation Slides
DevSecCon SG 2018 Fabian Presentation SlidesDevSecCon SG 2018 Fabian Presentation Slides
DevSecCon SG 2018 Fabian Presentation Slides
 
Asynchronous single page applications without a line of HTML or Javascript, o...
Asynchronous single page applications without a line of HTML or Javascript, o...Asynchronous single page applications without a line of HTML or Javascript, o...
Asynchronous single page applications without a line of HTML or Javascript, o...
 
Domain Driven Design Tactical Patterns
Domain Driven Design Tactical PatternsDomain Driven Design Tactical Patterns
Domain Driven Design Tactical Patterns
 
Gradle 101
Gradle 101Gradle 101
Gradle 101
 
Gradle build capabilities
Gradle build capabilities Gradle build capabilities
Gradle build capabilities
 
IDE and Toolset For Magento Development
IDE and Toolset For Magento DevelopmentIDE and Toolset For Magento Development
IDE and Toolset For Magento Development
 
Tahoe Dreamin 2018: It simply works... until it breaks!
Tahoe Dreamin 2018: It simply works... until it breaks!Tahoe Dreamin 2018: It simply works... until it breaks!
Tahoe Dreamin 2018: It simply works... until it breaks!
 
Landing code in curl
Landing code in curlLanding code in curl
Landing code in curl
 
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLEAN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
 
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE - CFObjective() 2017
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE - CFObjective() 2017AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE - CFObjective() 2017
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE - CFObjective() 2017
 
Big code refactoring with agility
Big code refactoring with agilityBig code refactoring with agility
Big code refactoring with agility
 
ICONUK 2015 - Gradle Up!
ICONUK 2015 - Gradle Up!ICONUK 2015 - Gradle Up!
ICONUK 2015 - Gradle Up!
 

Recently uploaded

the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 

Recently uploaded (20)

★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 

Let Codenarc check if you write good Groovy code

  • 1. Salenda Let Codenarc check if you
 write good code Greach ‘18 Alberto De Ávila Hernández
  • 2. A B O U T M E ✴ Software Engineer ✴ Team Lead at Salenda ✴ Groovy & Grails dev @alberto_deavila
  • 3. S A L E N D A
  • 4. S O F T WA R E D E V E L O P M E N T Turnkey development Atlassian Solution Partner Consulting and support in software architecture and analysis Application integration Evolutionary support of our own developments or inherited ones @alberto_deavila
  • 5. G O A L S Goals
  • 6. G O A L S ✴ Write better code ✴ Learn good practices ✴ Use only one code style criteria ✴ Fix code errors ✴ Don’t Repeat Yourself ✴ Clean code @alberto_deavila
  • 7. ✴ What’s Codenarc? ✴ Why should you use Codenarc? ✴ Rules ✴ Config in Grails 3 ✴ Custom rules I N D E X @alberto_deavila
  • 8. W H AT ’ S C O D E N A R C ? What’s Codenarc?
  • 9. ✴ Static code analysis tool for Groovy ✴ Similar to PMD or Checkstyle ✴ Opensource ✴ Check coding standards and best practices ✴ Flexible: rules, rulesets and custom rules ✴ Generates an HTML or XML report W H AT ’ S C O D E N A R C ? @alberto_deavila
  • 10. ✴ Analyzes: ✴ Defects ✴ Bad practices ✴ Inconsistencies ✴ Style issues ✴ … W H AT ’ S C O D E N A R C ? @alberto_deavila
  • 11. W H Y S H O U L D Y O U U S E C O D E N A R C ? Why should you use Codenarc?
  • 12. W H Y S H O U L D I U S E C O D E N A R C ? @alberto_deavila ✴ In a projects works many programmers ✴ Each person has different style programming ✴ Not all best practices are known ✴ Programmers need tools to check its work ✴ The team can define the rules to apply ✴ Improve your project in many ways
  • 13. R U L E S Rules
  • 14. R U L E S @alberto_deavila What’s a rule?
  • 15. R U L E S @alberto_deavila A function that looks at our code to check if it meets some conditions
  • 16. R U L E S @alberto_deavila What’s a ruleset?
  • 17. R U L E S @alberto_deavila A group of rules of the same type
  • 18. ✴ CodeNarc includes 357 rules ✴ Splited in 22 rulesets ✴ You can contribute with new rules: 
 https://github.com/CodeNarc/CodeNarc R U L E S @alberto_deavila
  • 19. R U L E S @alberto_deavila What kind of rules are defined?
  • 20. ✴ Basic: empty blocks/classes and many others ✴ DRY: repeated data like strings, numbers… ✴ Exceptions: alert about bad uses of exceptions ✴ Formatting: spaces, docs, blank lines… ✴ Grails: domain with service, duplicate constraints and mapping, mass assignment… R U L E S @alberto_deavila
  • 21. ✴ Groovyism: explicit calls, GString map keys ✴ JUnit: ignoreRest, unnecessary fails… ✴ Naming: validate the files and classes names ✴ Size: methods with too many params, methods too larges… ✴ Unused: unused variables, methods… R U L E S @alberto_deavila
  • 22. ✴ Braces ✴ Concurrency ✴ Convention ✴ Design ✴ Enhanced ✴ Generic R U L E S @alberto_deavila ✴ Imports ✴ JDBC ✴ Logging ✴ Security ✴ Serialization ✴ Unnecessary
  • 23. R U L E S @alberto_deavila Rules configuration
  • 24. ✴ Common configuration: ✴ enabled = false ✴ applyToClassNames = ‘*Service’ ✴ doNotApplyToClassNames = ‘*Spec,*Util’ ✴ priority = 1 ✴ Some rules can be configured particularly R U L E S @alberto_deavila
  • 25. C O N F I G I N G R A I L S 3 Config in Grails 3
  • 26. C O N F I G I N G R A I L S 3 @alberto_deavila ✴ Add plugin to build.gradle : apply plugin: 'codenarc' codenarc { toolVersion = '0.27.0' configFile = file("${rootProject.projectDir}/config/codenarc/ rules.groovy") reportFormat = 'html' ignoreFailures = true }
  • 27. C O N F I G I N G R A I L S 3 @alberto_deavila ✴ Create the rules file: 
 
 
 
 
 ruleset { description 'Grails-CodeNarc Project RuleSet' ruleset('rulesets/basic.xml') ruleset('rulesets/braces.xml') ruleset('rulesets/grails.xml') }
  • 28. C O N F I G I N G R A I L S 3 @alberto_deavila ✴ Execute $ ./gradlew app:check ✴ Open test report to check violations:
  • 29. C U S T O M R U L E S Custom rules
  • 30. C U S T O M R U L E S @alberto_deavila ✴ Define the ruleset: <ruleset xmlns="http://codenarc.org/ruleset/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://codenarc.org/ruleset/1.0 http:// codenarc.org/ruleset-schema.xsd" xsi:noNamespaceSchemaLocation="http://codenarc.org/ruleset- schema.xsd"> <description>Extra Grails rules</description> <rule class='org.codenarc.rule.grails.GrailsTransactionalRule'/> </ruleset>
  • 31. C U S T O M R U L E S @alberto_deavila ✴ Create the rule config: class GrailsTransactionalRule extends AbstractAstVisitorRule { int priority = 2 String name = 'GrailsTransactional' Class astVisitorClass = GrailsTransactionalVisitor }
  • 32. C U S T O M R U L E S @alberto_deavila ✴ Create the rule implementation: @CompileStatic class GrailsTransactionalVisitor extends AbstractAstVisitor { @Override void visitAnnotations(AnnotatedNode node) { node.annotations.each { AnnotationNode annotationNode -> String annotation = annotationNode.classNode.text if (annotation == “org.springframework.transaction.annotation.Transactional”) { addViolation(node, “Error msg”) } } super.visitAnnotations(node) } }
  • 33. C U S T O M R U L E S @alberto_deavila ✴ Create a Gradle project with that rule ✴ Some other config needed ✴ More info: http://guides.grails.org/grails-codenarc/guide/ index.html#writingCustomRule
  • 34. C O N C L U S I O N S Conclusions
  • 35. C O N C L U S I O N S @alberto_deavila ✴ Easy to configure and use ✴ Show us a lot of information ✴ Customize the rules to apply ✴ Create your own rules ✴ Maintains a unified code style ✴ You should use it
  • 36. M O R E I N F O @alberto_deavila ✴ Grails Guide: 
 http://guides.grails.org/grails-codenarc/ guide/index.html ✴ Codenarc doc: 
 http://codenarc.sourceforge.net/ ✴ Codenarc repo: 
 https://github.com/CodeNarc/CodeNarc