Google Summer of Code 2018 Work Product Submission



coala

Viresh Gupta

Hi ! I am Viresh Gupta, an undergrad student at Indraprastha Institute of Information Technology, Delhi, India. I love coding in and out and like to lay my hands on whatever tech I can find. I also love to read books, observe nature and star gaze in my free time. I chose coala for my GSoC project because I think it’s awesome to be able to push my friends a friendly reminder to indent their code properly, and programmatically detect when they went lazy in doing so, which helps me to focus on the main logic when working on a team project.


Patches Tarball


SHA-256:

43cd5aaf56b735abf34bba8fbf9f83f2cba716c9f20f76c3954228887f61e220

Bonding

Phase 1

Phase 2

Phase 3


Links to commits and repositories I've worked on:

Repository Link to Commit/s Description
c  cEPs View

“cEP-0018: Integration of ANTLR in coala”

c  cEPs View

“cEP-0018.md: Add information about fixes”

c  coala-antlr View

“Initial Commit”

c  coala-antlr View

“ci: Integrate inital ci test”

c  coala-antlr View

“setup.py: Make package installable”

c  coala-antlr View

“Implement a loader for parse trees”

c  coala-antlr View

“Initial walkers implemented,”

c  coala-antlr View

“core: Add ASTBear and Implement quote spacing bear”

c  coala-antlr View

“.gitlab-ci.yml: Add job for bear run testing”

c  coala-antlr View

“PyQuoteSpacingBear: Fix for implicit string concatenation”

c  coala-antlr View

“.gitlab-ci: Add moban check”

c  coala-antlr View

“Add initial tests”

c  coala-antlr View

“Change the library logic for visiting”

c  coala-antlr View

“Add pytest with 100% coverage”

c  coala-antlr View

“.coafile: Add initial coafile”

c  coala-antlr View

“setup.py: Add entrypoint for bear discovery”

c  coala-antlr View

“PyQuoteSpacingBearTest.py: Add tests for slash”

c  coala-antlr View

“PyPluralNamingBear: Add Bear”

c  coala-antlr View

“MANIFEST: Add manifest and housekeeping”

c  coala-antlr View

“Py3Walker: Use NodeData for get_quote_content”

c  coala-antlr View

“Add sphinx docs”

c  coala-antlr View

“Add coantbears docs”

c  coala-antlr View

“Add docs for gitlab pages”

c  coala-antlr View

“Add bears metadata and refactor dependencies”

c  coala-antlr View

“ASTLoader: Workaround for python”

c  coala-antlr View

“ASTLoader.py: Add check for empty files”

c  coala-antlr View

“coantlib: Move all generated files”

c  coala-antlr View

“commonutils.py: Extract common utilities”

c  coala-antlr View

“.coafile: Add PyDocStyleBear”

c  coala-antlr View

“.gitlab-ci.yml: Add git installation”

c  coala-antlr View

“coantlib: Generalise entrypoint”

c  coala-antlr View

“tests: Remove hashbangs”

c  coala-antlr View

“Python3.py: Make parser PEP8 compliant”

c  coala-antlr View

“ASTBear: Remove redundant lang argument”

c  coala-antlr View

“XMLIndentBear: Add XMLIndentBear”

c  coala-antlr View

“.ci: Add check for XML Upstream grammar”

c  coala View

“XML.py: Add language definition for XML”

c  community View

“.coafile: Add PyPluralNamingBear”

c  coala-quickstart View

“appveyor.yml: Use pip as a module”

c  coala-quickstart View

“test-requirements.txt: Add packaging”

c  coala-bears View

“GitCommitBear: Refactor issue regexes”

c  coala-bears View

“GitCommitBear: Add BitBucket type issue references”

c  coala-bears View

“HgCommitBear: Switch to git-url-parse”

p  projects View

“report.md: Make GSoC year dynamic”

c  coala-mobans View

“appveyor.yml.jj2: Add template for appveyor config”

g  git-url-parse View

“conftest.py: Add test for BitBucket style git url”

g  grammars-v4 View

“Python3.g4: Add support for newer python features”


Integrate ANTLR with coala

This project is about integrating ANTLR with coala. coala is a one stop linter, which provides unified API to lint several languages, and it also provides an API to create our own Analysis over code. ANTLR is ANother Tool for Language Recognition, which helps us to create parse trees and provides api for traversing those parse trees.

This project aims to combine the capabilities of the two tools which will enable coala users to write advanced analysis logic using parse trees and vastly improve the capabilities of Native Bears of coala (Native bears do not depend on any external linting tools).

As an outcome of this project, coala will be able to support any arbitrary language, provided there exists a grammar for it, and thus this project is a step towards the future of native bear development with coala.

Library availaible at: https://gitlab.com/coala/bears/coala-antlr Docs hosted at: https://virresh.gitlab.io/coala-antlr/

Work Done

coala-antlr

A library for integrating ANTLR with coala was created and as a proof of utility, few analysis tools were created for Python language, and one of them was also put to Production for improved maintenance. A bear for analysing XML language is also ready and acts as an example of the capabilities of this library to support multiple grammars.

PyQuoteSpacingBear - This bear checks for trailing spaces in all the strings in a python source code.

PyPluralNamingBear - This bear enforces variables that have been assigned to a list or a dictionary to have a plural name.

XMLIndentBear - This bear will analyse indents in an XML file and suggest appropriate fixes for getting tags to indent at same level.

This library is now usable by bear writers for writing native bears for coala while leveraging the power of ANTLR. (All commits included as diff patches in the tarball)

antlr-v4-grammars

Some issues were identified with the upstream grammars and were reported, along with suggested corrections as PR. Link

community

Add PyPluralNamingBear to repo, for confirming the feasibility and ease of use of the library.

coala

Minor enhancements were made such as adding a language definition for XML, which coala-antlr requires for it’s XMLIndentBear.

coala-mobans

Added a template for standardising appveyor CI configurations across repos.

coala-bears

Added support for Mercurial via a HgCommitBear. Enhanced existing GitCommitBear with improved logging.

All contributions apart from coala-antlr repo present as diff patches of commits.

Challenges

Major challenge in the project for me was to come up with a library design that’s flexible enough to support all grammars, and yet powerful enough to leverage all features provided by a grammar.

I was guided by my mentor Dong-hee and my org admin John through important design decisions and they helped me to come up with a flexible design.

The other major challenge was using grammars that are directly from the upstream grammars repository. Several errors were identified in the upstream repository and we had to find out workarounds for most issues. This is a more prominent problem for places where we needed to provide a fix for the linting issue identified.

Work to be done

The library is up and ready to roll, although by itself it won’t be much useful unless people use it to write bears for coala. So the future work on this library would involve having lots of bears written for various grammars

Also enhancements possible in the library would involve a mechanism that would help the bear writers to suggest complex fixes easily, although this would probably have to wait until antlr supports tree rewriting or workarounds are discovered to deal with source code retrieval from parse tree.

Another possible enhancement in the library would be the feature of on-demand grammar download, which essentially means we would be able to make the process of adding more languages to coala-antlr easier, by not having to worry about adding parsers and lexers manually when a language is added for the first time.