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 à Coding with style: The Scalastyle style checker

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. Adform Research
Testing in Scala. Adform ResearchTesting in Scala. Adform Research
Testing in Scala. Adform ResearchVasil Remeniuk
 
Testing in Scala by Adform research
Testing in Scala by Adform researchTesting in Scala by Adform research
Testing in Scala by 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 à Coding with style: The Scalastyle style checker (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. Adform Research
Testing in Scala. Adform ResearchTesting in Scala. Adform Research
Testing in Scala. Adform Research
 
Testing in Scala by Adform research
Testing in Scala by Adform researchTesting in Scala by Adform research
Testing in Scala by 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

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 

Dernier (20)

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 

Coding with style: The Scalastyle style checker

  • 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.