SlideShare une entreprise Scribd logo
1  sur  19
Télécharger pour lire hors ligne
Scala Code Analysis at Codacy
before and after scala.meta
Johann Egger
intro
‣ static code analysis
‣ supporting various languages via open source tools
‣ in-house scala engine
outline
‣ history/evolution of the scala engine
‣ user defined patterns
‣ live demo
naming conventions / keywords
‣ AST: Abstract syntax tree - syntactic structure of program
‣ Pattern: AST => Set of code-positions containing issues
‣ quasiquote: templates that allow matching trees
restrictions/boundaries
‣ analysis of single source file
‣ analysis of source code ( != object code )
phase 0
universal ast
‣ unifying various languages
generic patterns
patterns only in theory useful
no language specific information
phase 1
scala.reflect + javascript
‣ scala reflection toolbox parses source
‣ AST converted to JSON
‣ javascript patterns run in node.js
scala.reflect + javascript
all scala language constructs in AST
expressive patterns
run in browser
complex AST
complex patterns
var utils = CodacyEngine.getInstance();
var astUtils = ScalaAstOps.getInstance();
var hasDeferredImpl = function(element){
return _.isArray(element.templ.body) &&
_.some(element.templ.body, function(bodyElem){
return astUtils.hasFlag(bodyElem,"deferred");
});
};
var isStructuralTypeDef = function(element){
return astUtils.isCompoundTypeTree(element) &&
hasDeferredImpl(element);
};
var getElements = function(element){
return astUtils.allInTreeWhere(element, isStructuralTypeDef);
};
utils.analyse = function(ast){
_.map(
ast.fileNodes,
function(fileNode){
_.map(
getElements(fileNode),
function (nestedIfElement) {
utils.addWarning(fileNode.filename,
nestedIfElement.line, nestedIfElement.line,
"Avoid using structural types");
}
);
}
);
return utils.finalResult();
};
ClassDef(
Modifiers(
ABSTRACT
),
TypeName(
"Foo"
),
List(),
Template(
List(
Select(
Ident(
scala
),
TypeName(
"AnyRef"
)
)
),
noSelfType,
List(
DefDef(
Modifiers(),
termNames.CONSTRUCTOR,
List(),
List(
List( )
),
TypeTree(),
Block(
List(
pendingSuperCall
),
Literal(
Constant(
( )
)
)
)
),
TypeDef(
Modifiers(),
TypeName(
…
abstract class Foo{
type BarType = AnyRef { def bar:String }
}
scala test code
javascript pattern code
scala.reflect AST
phase 2
scala.meta + quasiquotes
‣ "make metaprogramming easy”
‣ scala.meta parses sources
‣ patterns written using quasiquotes
‣ > 80 patterns implemented
scala.meta + quasiquotes
easy to write patterns (scala patterns for scala code)
runs faster (no javascript indirection)
no client-side pattern execution
user defined patterns
‣ write and test patterns online
‣ no IDE needed
‣ allows finding very specific issues
>_
example: ===
‣ 1 == “1” should not compile
‣ find all occurrences of ==
‣ emit a warning and suggest using === instead
thank you!
johann@codacy.com
links
‣ codacy: https://codacy.com/
‣ scala.meta: http://scalameta.org/
‣ scala.meta presentation: https://www.youtube.com/watch?v=RBjZ7OxFxxg
‣ quasiquotes: https://github.com/scalameta/scalameta/blob/master/docs/quasiquotes.md

Contenu connexe

Tendances

JavaScript (without DOM)
JavaScript (without DOM)JavaScript (without DOM)
JavaScript (without DOM)
Piyush Katariya
 

Tendances (20)

15 Minutes Null
15 Minutes Null15 Minutes Null
15 Minutes Null
 
Advanced Reflection in Pharo
Advanced Reflection in PharoAdvanced Reflection in Pharo
Advanced Reflection in Pharo
 
Java2 days 2013-lambda
Java2 days 2013-lambdaJava2 days 2013-lambda
Java2 days 2013-lambda
 
Variables in Pharo5
Variables in Pharo5Variables in Pharo5
Variables in Pharo5
 
Roslyn
RoslynRoslyn
Roslyn
 
Introduction to java 8 stream api
Introduction to java 8 stream apiIntroduction to java 8 stream api
Introduction to java 8 stream api
 
JavaScript (without DOM)
JavaScript (without DOM)JavaScript (without DOM)
JavaScript (without DOM)
 
Scala on-android
Scala on-androidScala on-android
Scala on-android
 
Java 8 - Project Lambda
Java 8 - Project LambdaJava 8 - Project Lambda
Java 8 - Project Lambda
 
Streams or Loops? Java 8 Stream API by Niki Petkov - Proxiad Bulgaria
Streams or Loops? Java 8 Stream API by Niki Petkov - Proxiad BulgariaStreams or Loops? Java 8 Stream API by Niki Petkov - Proxiad Bulgaria
Streams or Loops? Java 8 Stream API by Niki Petkov - Proxiad Bulgaria
 
Introduction to Scala language
Introduction to Scala languageIntroduction to Scala language
Introduction to Scala language
 
JavaScript Object Oriented Programming Cheat Sheet
JavaScript Object Oriented Programming Cheat SheetJavaScript Object Oriented Programming Cheat Sheet
JavaScript Object Oriented Programming Cheat Sheet
 
RxJS - The Reactive Extensions for JavaScript
RxJS - The Reactive Extensions for JavaScriptRxJS - The Reactive Extensions for JavaScript
RxJS - The Reactive Extensions for JavaScript
 
Introduction to Object Oriented Javascript
Introduction to Object Oriented JavascriptIntroduction to Object Oriented Javascript
Introduction to Object Oriented Javascript
 
Introduction to RxJava on Android
Introduction to RxJava on AndroidIntroduction to RxJava on Android
Introduction to RxJava on Android
 
Attacking GraphQL
Attacking GraphQLAttacking GraphQL
Attacking GraphQL
 
Programming in Spark - Lessons Learned in OpenAire project
Programming in Spark - Lessons Learned in OpenAire projectProgramming in Spark - Lessons Learned in OpenAire project
Programming in Spark - Lessons Learned in OpenAire project
 
GraphQL Misconfiguration
GraphQL MisconfigurationGraphQL Misconfiguration
GraphQL Misconfiguration
 
Swift, a quick overview
Swift, a quick overviewSwift, a quick overview
Swift, a quick overview
 
Reflection in Pharo5
Reflection in Pharo5Reflection in Pharo5
Reflection in Pharo5
 

En vedette

Congreso mundial judío
Congreso mundial judíoCongreso mundial judío
Congreso mundial judío
Ramón Copa
 
Lodha Evoq - Sample Residence
Lodha Evoq - Sample ResidenceLodha Evoq - Sample Residence
Lodha Evoq - Sample Residence
snehal2671
 
Newsletterajul10[1]
Newsletterajul10[1]Newsletterajul10[1]
Newsletterajul10[1]
Usapeec
 

En vedette (20)

E seminarium nyttorealisering 111125
E seminarium nyttorealisering 111125E seminarium nyttorealisering 111125
E seminarium nyttorealisering 111125
 
25 de mayo tiempos del bicentenario
25 de mayo   tiempos del bicentenario25 de mayo   tiempos del bicentenario
25 de mayo tiempos del bicentenario
 
KITAB SI SHU AGAMA KHONGHUCU
KITAB SI SHU AGAMA KHONGHUCUKITAB SI SHU AGAMA KHONGHUCU
KITAB SI SHU AGAMA KHONGHUCU
 
Virtues of-quranppt
Virtues of-quranpptVirtues of-quranppt
Virtues of-quranppt
 
Ivo Pezzuto - The “Miracle” Still Goes On For Someone…(Dr. Ivo Pezzuto and Dr...
Ivo Pezzuto - The “Miracle” Still Goes On For Someone…(Dr. Ivo Pezzuto and Dr...Ivo Pezzuto - The “Miracle” Still Goes On For Someone…(Dr. Ivo Pezzuto and Dr...
Ivo Pezzuto - The “Miracle” Still Goes On For Someone…(Dr. Ivo Pezzuto and Dr...
 
crisis de 1929
crisis de 1929crisis de 1929
crisis de 1929
 
Congreso mundial judío
Congreso mundial judíoCongreso mundial judío
Congreso mundial judío
 
Leandro Gómez
Leandro GómezLeandro Gómez
Leandro Gómez
 
Festa junina 2016
Festa junina 2016Festa junina 2016
Festa junina 2016
 
Enlaces diana luna
Enlaces diana lunaEnlaces diana luna
Enlaces diana luna
 
Porcelanosa
PorcelanosaPorcelanosa
Porcelanosa
 
Lodha Evoq - Sample Residence
Lodha Evoq - Sample ResidenceLodha Evoq - Sample Residence
Lodha Evoq - Sample Residence
 
Newsletterajul10[1]
Newsletterajul10[1]Newsletterajul10[1]
Newsletterajul10[1]
 
America & cuba
America & cubaAmerica & cuba
America & cuba
 
Revista Regio nr.31
Revista Regio nr.31Revista Regio nr.31
Revista Regio nr.31
 
Идея!
Идея!Идея!
Идея!
 
Tv shot semana 7
Tv shot semana 7Tv shot semana 7
Tv shot semana 7
 
Parcial
ParcialParcial
Parcial
 
COOKS Infographic
COOKS InfographicCOOKS Infographic
COOKS Infographic
 
Noti ghiray
Noti ghirayNoti ghiray
Noti ghiray
 

Similaire à Scala Code Analysis at Codacy

Typesafe stack - Scala, Akka and Play
Typesafe stack - Scala, Akka and PlayTypesafe stack - Scala, Akka and Play
Typesafe stack - Scala, Akka and Play
Luka Zakrajšek
 
Open Source Compiler Construction for the JVM
Open Source Compiler Construction for the JVMOpen Source Compiler Construction for the JVM
Open Source Compiler Construction for the JVM
Tom Lee
 
Server Side Javascript
Server Side JavascriptServer Side Javascript
Server Side Javascript
rajivmordani
 

Similaire à Scala Code Analysis at Codacy (20)

Quick introduction to scala
Quick introduction to scalaQuick introduction to scala
Quick introduction to scala
 
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
 
Alberto Paro - Hands on Scala.js
Alberto Paro - Hands on Scala.jsAlberto Paro - Hands on Scala.js
Alberto Paro - Hands on Scala.js
 
Scala Italy 2015 - Hands On ScalaJS
Scala Italy 2015 - Hands On ScalaJSScala Italy 2015 - Hands On ScalaJS
Scala Italy 2015 - Hands On ScalaJS
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and Xitrum
 
Typesafe stack - Scala, Akka and Play
Typesafe stack - Scala, Akka and PlayTypesafe stack - Scala, Akka and Play
Typesafe stack - Scala, Akka and Play
 
Typescript in 30mins
Typescript in 30mins Typescript in 30mins
Typescript in 30mins
 
Scala's evolving ecosystem- Introduction to Scala.js
Scala's evolving ecosystem- Introduction to Scala.jsScala's evolving ecosystem- Introduction to Scala.js
Scala's evolving ecosystem- Introduction to Scala.js
 
Module Ninja .JS
Module Ninja .JSModule Ninja .JS
Module Ninja .JS
 
Sviluppare applicazioni nell'era dei "Big Data" con Scala e Spark - Mario Car...
Sviluppare applicazioni nell'era dei "Big Data" con Scala e Spark - Mario Car...Sviluppare applicazioni nell'era dei "Big Data" con Scala e Spark - Mario Car...
Sviluppare applicazioni nell'era dei "Big Data" con Scala e Spark - Mario Car...
 
Don't Be Afraid of Abstract Syntax Trees
Don't Be Afraid of Abstract Syntax TreesDon't Be Afraid of Abstract Syntax Trees
Don't Be Afraid of Abstract Syntax Trees
 
A Tour Of Scala
A Tour Of ScalaA Tour Of Scala
A Tour Of Scala
 
Java SE 8 & EE 7 Launch
Java SE 8 & EE 7 LaunchJava SE 8 & EE 7 Launch
Java SE 8 & EE 7 Launch
 
The Parenscript Common Lisp to JavaScript compiler
The Parenscript Common Lisp to JavaScript compilerThe Parenscript Common Lisp to JavaScript compiler
The Parenscript Common Lisp to JavaScript compiler
 
React Component in scala.js
React Component in scala.jsReact Component in scala.js
React Component in scala.js
 
Open Source Compiler Construction for the JVM
Open Source Compiler Construction for the JVMOpen Source Compiler Construction for the JVM
Open Source Compiler Construction for the JVM
 
Server Side Javascript
Server Side JavascriptServer Side Javascript
Server Side Javascript
 
Introduction to Scala : Clueda
Introduction to Scala : CluedaIntroduction to Scala : Clueda
Introduction to Scala : Clueda
 
User Interface
User InterfaceUser Interface
User Interface
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 

Dernier

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Dernier (20)

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

Scala Code Analysis at Codacy

  • 1. Scala Code Analysis at Codacy before and after scala.meta Johann Egger
  • 2. intro ‣ static code analysis ‣ supporting various languages via open source tools ‣ in-house scala engine
  • 3. outline ‣ history/evolution of the scala engine ‣ user defined patterns ‣ live demo
  • 4. naming conventions / keywords ‣ AST: Abstract syntax tree - syntactic structure of program ‣ Pattern: AST => Set of code-positions containing issues ‣ quasiquote: templates that allow matching trees
  • 5. restrictions/boundaries ‣ analysis of single source file ‣ analysis of source code ( != object code )
  • 7. universal ast ‣ unifying various languages generic patterns patterns only in theory useful no language specific information
  • 9. scala.reflect + javascript ‣ scala reflection toolbox parses source ‣ AST converted to JSON ‣ javascript patterns run in node.js
  • 10. scala.reflect + javascript all scala language constructs in AST expressive patterns run in browser complex AST complex patterns
  • 11. var utils = CodacyEngine.getInstance(); var astUtils = ScalaAstOps.getInstance(); var hasDeferredImpl = function(element){ return _.isArray(element.templ.body) && _.some(element.templ.body, function(bodyElem){ return astUtils.hasFlag(bodyElem,"deferred"); }); }; var isStructuralTypeDef = function(element){ return astUtils.isCompoundTypeTree(element) && hasDeferredImpl(element); }; var getElements = function(element){ return astUtils.allInTreeWhere(element, isStructuralTypeDef); }; utils.analyse = function(ast){ _.map( ast.fileNodes, function(fileNode){ _.map( getElements(fileNode), function (nestedIfElement) { utils.addWarning(fileNode.filename, nestedIfElement.line, nestedIfElement.line, "Avoid using structural types"); } ); } ); return utils.finalResult(); }; ClassDef( Modifiers( ABSTRACT ), TypeName( "Foo" ), List(), Template( List( Select( Ident( scala ), TypeName( "AnyRef" ) ) ), noSelfType, List( DefDef( Modifiers(), termNames.CONSTRUCTOR, List(), List( List( ) ), TypeTree(), Block( List( pendingSuperCall ), Literal( Constant( ( ) ) ) ) ), TypeDef( Modifiers(), TypeName( … abstract class Foo{ type BarType = AnyRef { def bar:String } } scala test code javascript pattern code scala.reflect AST
  • 13. scala.meta + quasiquotes ‣ "make metaprogramming easy” ‣ scala.meta parses sources ‣ patterns written using quasiquotes ‣ > 80 patterns implemented
  • 14. scala.meta + quasiquotes easy to write patterns (scala patterns for scala code) runs faster (no javascript indirection) no client-side pattern execution
  • 15. user defined patterns ‣ write and test patterns online ‣ no IDE needed ‣ allows finding very specific issues
  • 16. >_
  • 17. example: === ‣ 1 == “1” should not compile ‣ find all occurrences of == ‣ emit a warning and suggest using === instead
  • 19. links ‣ codacy: https://codacy.com/ ‣ scala.meta: http://scalameta.org/ ‣ scala.meta presentation: https://www.youtube.com/watch?v=RBjZ7OxFxxg ‣ quasiquotes: https://github.com/scalameta/scalameta/blob/master/docs/quasiquotes.md