SlideShare une entreprise Scribd logo
1  sur  15
The style checker for Scala
Scala Days 2012
Matthew Farwell @matthewfarwell
                  @scalastyle
Matthew Farwell

Java technical expert @ SQLI Suisse in Lausanne
> 20 years development in various languages from Fortran
to Java/Scala
Contributor to various OSS projects, scala-ide, Junit, and
of course Scalastyle
Enjoying Scala Days 2012!
The plan

Why
What
Demo
How
What next?
Why an automated style checker?
Douglas Crockford: "All languages should have a lint".
Problem: too many people
Problem: too many lines of code


Solution: code reviews?
Solution: style guides?
Solution: unit tests?
Solution: integration tests?
Solution: fewer lines of code?
Solution: Scalastyle?
What is Scalastyle?
Scalastyle is a style checker, similar to
Checkstyle, including bits of Findbugs & PMD.


There is a continuum of checks that we need to make on
our code, but which shouldn’t belong in the compiler.


Projects are different, so everything needs to be
configurable.


They are just guidelines, they aren’t rules. But they can
rules be for your project.
What does it check? Format rules
Heavily inspired by Checkstyle
Format rules:
 Files do not contain tabs
 Files contain correct headers, license and disclaimer etc.
 General format rules:
    def foo[T](t: T) = fn(t) + 3
    not
    def foo [ T ] (t : T    ) = fn(t)+3
What does it check? Style rules
Style rules (house style, things which make the code
harder to understand or more complex):
Methods do not have more than x parameters
Number of classes in a file
Null not used
Return not used
Use of structural types
What does it check? Known sources of
bugs
Known sources of bugs, things to avoid:
A class/object implements equals() but not hashCode() or
vice versa
A class/object implements a covariant equals(x) but not
equals(Any)
Missing case default
Structural types
What can’t it do?
Anything which you don’t specify in the scala file.
Inferred types
Mismatches between types
Implicit conversions
Multi-file checks. Scalastyle only does one file at a time
Demo
Eclipse plugin – configuration & usage
Command line tool
// scalastyle:off magic.number
How
The excellent Scalariform. This gives us an AST and/or list
of tokens.
Lines: (list of lines)


We don’t use compiler plugins for these (main) reasons:
Speed (we can check scala compiler & library (1500 files)
in ~80s)
Comments (they get swallowed by the compiler)
for comprehensions get desugared
The Compiler Plugin API isn’t fully nailed down.
Rules which are currently implemented
FileLengthChecker - Check the number of lines in a file
FileLineLengthChecker - Check the number of characters in a line
FileTabChecker - Check that there are no tabs in a file
HeaderMatchesChecker - Check the first lines of each file matches the text
WhitespaceEndOfLineChecker - Check that there is no trailing whitespace at
the end of lines
ClassNamesChecker - Check that class names match a regular expression
CovariantEqualsChecker - Check that classes and objects do not define
equals without overriding equals(java.lang.Object).
EqualsHashCodeChecker - Check that if a class implements either equals or
hashCode, it should implement the other
IllegalImportsChecker - Check that a class does not import certain classes
Rules which are currently implemented
IllegalImportsChecker - Check that a class does not import certain classes
MagicNumberChecker - Checks for use of magic numbers
NoCloneChecker - Check that classes and objects do not define the clone() method
NoFinalizeChecker - Check that classes and objects do not define the finalize() method
NoWhitespaceAfterLeftBracketChecker - No whitespace after left bracket [
NoWhitespaceBeforeLeftBracketChecker - No whitespace before left bracket [
NullChecker - Check that null is not used
ObjectNamesChecker - Check that object names match a regular expression
ParameterNumberChecker - Maximum number of Parameters for a method
ReturnChecker - Check that return is not used
SpacesAfterPlusChecker - Check that the plus sign is followed by a space
SpacesBeforePlusChecker - Check that the plus sign is preceded by a space
StructuralTypeChecker - Check that structural types are not used
RegexChecker – Check that no line matches a defined regular expression
How do I get involved?
Me: Matthew Farwell @matthewfarwell
Fork us on github: https://github.com/scalastyle/scalastyle
List of rules to implement:
https://github.com/scalastyle/scalastyle/wiki
User mailing list: scalastyle-users@googlegroups.com
Twitter: @scalastyle


Major pieces still needed: Maven plugin, Intellij plugin, sbt
plugin.
As always, documentation.
Questions?

Contenu connexe

Tendances

Introduction to Selenium and Ruby
Introduction to Selenium and RubyIntroduction to Selenium and Ruby
Introduction to Selenium and RubyYnon Perek
 
Test Driven Development with JavaFX
Test Driven Development with JavaFXTest Driven Development with JavaFX
Test Driven Development with JavaFXHendrik Ebbers
 
Your First Scala Web Application using Play 2.1
Your First Scala Web Application using Play 2.1Your First Scala Web Application using Play 2.1
Your First Scala Web Application using Play 2.1Matthew Barlocker
 
Jquery- One slide completing all JQuery
Jquery- One slide completing all JQueryJquery- One slide completing all JQuery
Jquery- One slide completing all JQueryKnoldus Inc.
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScriptYakov Fain
 
Dart for Java Developers
Dart for Java DevelopersDart for Java Developers
Dart for Java DevelopersYakov Fain
 
Intro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran MizrahiIntro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran MizrahiRan Mizrahi
 
Integration Testing With ScalaTest and MongoDB
Integration Testing With ScalaTest and MongoDBIntegration Testing With ScalaTest and MongoDB
Integration Testing With ScalaTest and MongoDBMichal Bigos
 
Testing in AngularJS
Testing in AngularJSTesting in AngularJS
Testing in AngularJSPeter Drinnan
 
Introduction to Protractor
Introduction to ProtractorIntroduction to Protractor
Introduction to ProtractorJie-Wei Wu
 
Unit Testing JavaScript Applications
Unit Testing JavaScript ApplicationsUnit Testing JavaScript Applications
Unit Testing JavaScript ApplicationsYnon Perek
 
Protractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applicationsProtractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applicationsLudmila Nesvitiy
 
Apache Ant
Apache AntApache Ant
Apache AntAli Bahu
 
Selenium Automation Using Ruby
Selenium Automation Using RubySelenium Automation Using Ruby
Selenium Automation Using RubyKumari Warsha Goel
 
Codegeneration With Xtend
Codegeneration With XtendCodegeneration With Xtend
Codegeneration With XtendSven Efftinge
 

Tendances (20)

Introduction to Selenium and Ruby
Introduction to Selenium and RubyIntroduction to Selenium and Ruby
Introduction to Selenium and Ruby
 
Test Driven Development with JavaFX
Test Driven Development with JavaFXTest Driven Development with JavaFX
Test Driven Development with JavaFX
 
Powershell training material
Powershell training materialPowershell training material
Powershell training material
 
Your First Scala Web Application using Play 2.1
Your First Scala Web Application using Play 2.1Your First Scala Web Application using Play 2.1
Your First Scala Web Application using Play 2.1
 
Jquery- One slide completing all JQuery
Jquery- One slide completing all JQueryJquery- One slide completing all JQuery
Jquery- One slide completing all JQuery
 
Testing Angular
Testing AngularTesting Angular
Testing Angular
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScript
 
Dart for Java Developers
Dart for Java DevelopersDart for Java Developers
Dart for Java Developers
 
Intro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran MizrahiIntro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran Mizrahi
 
Integration Testing With ScalaTest and MongoDB
Integration Testing With ScalaTest and MongoDBIntegration Testing With ScalaTest and MongoDB
Integration Testing With ScalaTest and MongoDB
 
Testing in AngularJS
Testing in AngularJSTesting in AngularJS
Testing in AngularJS
 
Introduction to Protractor
Introduction to ProtractorIntroduction to Protractor
Introduction to Protractor
 
Flask restless
Flask restlessFlask restless
Flask restless
 
Unit Testing JavaScript Applications
Unit Testing JavaScript ApplicationsUnit Testing JavaScript Applications
Unit Testing JavaScript Applications
 
PHP Unit Testing
PHP Unit TestingPHP Unit Testing
PHP Unit Testing
 
Protractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applicationsProtractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applications
 
Apache Ant
Apache AntApache Ant
Apache Ant
 
Life outside WO
Life outside WOLife outside WO
Life outside WO
 
Selenium Automation Using Ruby
Selenium Automation Using RubySelenium Automation Using Ruby
Selenium Automation Using Ruby
 
Codegeneration With Xtend
Codegeneration With XtendCodegeneration With Xtend
Codegeneration With Xtend
 

Similaire à The style checker for Scala: Scalastyle

Scala final ppt vinay
Scala final ppt vinayScala final ppt vinay
Scala final ppt vinayViplav Jain
 
A Tour Of Scala
A Tour Of ScalaA Tour Of Scala
A Tour Of Scalafanf42
 
Testing in Scala by Adform research
Testing in Scala by Adform researchTesting in Scala by Adform research
Testing in Scala by Adform researchVasil Remeniuk
 
Testing in Scala. Adform Research
Testing in Scala. Adform ResearchTesting in Scala. Adform Research
Testing in Scala. Adform ResearchVasil Remeniuk
 
Few minutes To better Code - Refactoring
Few minutes To better Code - RefactoringFew minutes To better Code - Refactoring
Few minutes To better Code - RefactoringDiaa Al-Salehi
 
RSpec and Rails
RSpec and RailsRSpec and Rails
RSpec and RailsAlan Hecht
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to ScalaRahul Jain
 
Scala Bay Meetup - The state of Scala code style and quality
Scala Bay Meetup - The state of Scala code style and qualityScala Bay Meetup - The state of Scala code style and quality
Scala Bay Meetup - The state of Scala code style and qualityJaime Jorge
 
Codingstandards matiar
Codingstandards matiarCodingstandards matiar
Codingstandards matiarMatiar Rahman
 
Getting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and DataGetting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and DataCory Foy
 
Introduction to Scala JS
Introduction to Scala JSIntroduction to Scala JS
Introduction to Scala JSKnoldus Inc.
 
C# 3.0 and LINQ Tech Talk
C# 3.0 and LINQ Tech TalkC# 3.0 and LINQ Tech Talk
C# 3.0 and LINQ Tech TalkMichael Heydt
 
Working with Legacy Code
Working with Legacy CodeWorking with Legacy Code
Working with Legacy CodeEyal Golan
 
Automating C# Coding Standards using StyleCop and FxCop
Automating C# Coding Standards using StyleCop and FxCopAutomating C# Coding Standards using StyleCop and FxCop
Automating C# Coding Standards using StyleCop and FxCopBlackRabbitCoder
 
Beginners overview of automated testing with Rspec
Beginners overview of automated testing with RspecBeginners overview of automated testing with Rspec
Beginners overview of automated testing with Rspecjeffrey1ross
 
How Scala promotes TDD
How Scala promotes TDDHow Scala promotes TDD
How Scala promotes TDDShai Yallin
 

Similaire à The style checker for Scala: Scalastyle (20)

Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
 
Scala final ppt vinay
Scala final ppt vinayScala final ppt vinay
Scala final ppt vinay
 
Code Metrics
Code MetricsCode Metrics
Code Metrics
 
A Tour Of Scala
A Tour Of ScalaA Tour Of Scala
A Tour Of Scala
 
Testing in Scala by Adform research
Testing in Scala by Adform researchTesting in Scala by Adform research
Testing in Scala by Adform research
 
Testing in Scala. Adform Research
Testing in Scala. Adform ResearchTesting in Scala. Adform Research
Testing in Scala. Adform Research
 
Few minutes To better Code - Refactoring
Few minutes To better Code - RefactoringFew minutes To better Code - Refactoring
Few minutes To better Code - Refactoring
 
RSpec and Rails
RSpec and RailsRSpec and Rails
RSpec and Rails
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Scala Bay Meetup - The state of Scala code style and quality
Scala Bay Meetup - The state of Scala code style and qualityScala Bay Meetup - The state of Scala code style and quality
Scala Bay Meetup - The state of Scala code style and quality
 
Apex code (Salesforce)
Apex code (Salesforce)Apex code (Salesforce)
Apex code (Salesforce)
 
Codingstandards matiar
Codingstandards matiarCodingstandards matiar
Codingstandards matiar
 
Getting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and DataGetting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and Data
 
Presentation
PresentationPresentation
Presentation
 
Introduction to Scala JS
Introduction to Scala JSIntroduction to Scala JS
Introduction to Scala JS
 
C# 3.0 and LINQ Tech Talk
C# 3.0 and LINQ Tech TalkC# 3.0 and LINQ Tech Talk
C# 3.0 and LINQ Tech Talk
 
Working with Legacy Code
Working with Legacy CodeWorking with Legacy Code
Working with Legacy Code
 
Automating C# Coding Standards using StyleCop and FxCop
Automating C# Coding Standards using StyleCop and FxCopAutomating C# Coding Standards using StyleCop and FxCop
Automating C# Coding Standards using StyleCop and FxCop
 
Beginners overview of automated testing with Rspec
Beginners overview of automated testing with RspecBeginners overview of automated testing with Rspec
Beginners overview of automated testing with Rspec
 
How Scala promotes TDD
How Scala promotes TDDHow Scala promotes TDD
How Scala promotes TDD
 

Dernier

Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 

Dernier (20)

Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 

The style checker for Scala: Scalastyle

  • 1. The style checker for Scala Scala Days 2012 Matthew Farwell @matthewfarwell @scalastyle
  • 2. Matthew Farwell Java technical expert @ SQLI Suisse in Lausanne > 20 years development in various languages from Fortran to Java/Scala Contributor to various OSS projects, scala-ide, Junit, and of course Scalastyle Enjoying Scala Days 2012!
  • 4. Why an automated style checker? Douglas Crockford: "All languages should have a lint". Problem: too many people Problem: too many lines of code Solution: code reviews? Solution: style guides? Solution: unit tests? Solution: integration tests? Solution: fewer lines of code? Solution: Scalastyle?
  • 5. What is Scalastyle? Scalastyle is a style checker, similar to Checkstyle, including bits of Findbugs & PMD. There is a continuum of checks that we need to make on our code, but which shouldn’t belong in the compiler. Projects are different, so everything needs to be configurable. They are just guidelines, they aren’t rules. But they can rules be for your project.
  • 6. What does it check? Format rules Heavily inspired by Checkstyle Format rules: Files do not contain tabs Files contain correct headers, license and disclaimer etc. General format rules: def foo[T](t: T) = fn(t) + 3 not def foo [ T ] (t : T ) = fn(t)+3
  • 7. What does it check? Style rules Style rules (house style, things which make the code harder to understand or more complex): Methods do not have more than x parameters Number of classes in a file Null not used Return not used Use of structural types
  • 8. What does it check? Known sources of bugs Known sources of bugs, things to avoid: A class/object implements equals() but not hashCode() or vice versa A class/object implements a covariant equals(x) but not equals(Any) Missing case default Structural types
  • 9. What can’t it do? Anything which you don’t specify in the scala file. Inferred types Mismatches between types Implicit conversions Multi-file checks. Scalastyle only does one file at a time
  • 10. Demo Eclipse plugin – configuration & usage Command line tool // scalastyle:off magic.number
  • 11. How The excellent Scalariform. This gives us an AST and/or list of tokens. Lines: (list of lines) We don’t use compiler plugins for these (main) reasons: Speed (we can check scala compiler & library (1500 files) in ~80s) Comments (they get swallowed by the compiler) for comprehensions get desugared The Compiler Plugin API isn’t fully nailed down.
  • 12. Rules which are currently implemented FileLengthChecker - Check the number of lines in a file FileLineLengthChecker - Check the number of characters in a line FileTabChecker - Check that there are no tabs in a file HeaderMatchesChecker - Check the first lines of each file matches the text WhitespaceEndOfLineChecker - Check that there is no trailing whitespace at the end of lines ClassNamesChecker - Check that class names match a regular expression CovariantEqualsChecker - Check that classes and objects do not define equals without overriding equals(java.lang.Object). EqualsHashCodeChecker - Check that if a class implements either equals or hashCode, it should implement the other IllegalImportsChecker - Check that a class does not import certain classes
  • 13. Rules which are currently implemented IllegalImportsChecker - Check that a class does not import certain classes MagicNumberChecker - Checks for use of magic numbers NoCloneChecker - Check that classes and objects do not define the clone() method NoFinalizeChecker - Check that classes and objects do not define the finalize() method NoWhitespaceAfterLeftBracketChecker - No whitespace after left bracket [ NoWhitespaceBeforeLeftBracketChecker - No whitespace before left bracket [ NullChecker - Check that null is not used ObjectNamesChecker - Check that object names match a regular expression ParameterNumberChecker - Maximum number of Parameters for a method ReturnChecker - Check that return is not used SpacesAfterPlusChecker - Check that the plus sign is followed by a space SpacesBeforePlusChecker - Check that the plus sign is preceded by a space StructuralTypeChecker - Check that structural types are not used RegexChecker – Check that no line matches a defined regular expression
  • 14. How do I get involved? Me: Matthew Farwell @matthewfarwell Fork us on github: https://github.com/scalastyle/scalastyle List of rules to implement: https://github.com/scalastyle/scalastyle/wiki User mailing list: scalastyle-users@googlegroups.com Twitter: @scalastyle Major pieces still needed: Maven plugin, Intellij plugin, sbt plugin. As always, documentation.