GithubHelp home page GithubHelp logo

codacy-acme / codacy-codesniffer-test2 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from codacy/codacy-codesniffer

0.0 0.0 0.0 1.01 MB

Codacy tool for PHP Codesniffer

License: Other

PHP 35.31% Scala 63.35% Dockerfile 1.35%

codacy-codesniffer-test2's Introduction

Codacy PHP_CodeSniffer

This is the docker engine we use at Codacy to have PHP_CodeSniffer support. You can also create a docker to integrate the tool and language of your choice! See the codacy-engine-scala-seed repository for more information.

Codacy Badge Build Status

Usage

You can create the docker by doing:

docker build -t codacy-codesniffer-base .
sbt docker:publishLocal

The docker is ran with the following command:

docker run -it -v $srcDir:/src  <DOCKER_NAME>:<DOCKER_VERSION>

Test

We use the codacy-plugins-test to test our external tools integration. You can follow the instructions there to make sure your tool is working as expected.

Generating the documentation

Requirements:

  • phpdoc

    curl -s http://getcomposer.org/installer | php
    php composer install
    composer global require phpdocumentor/phpdocumentor
    export PATH=$PATH:~/.composer/vendor/bin/

Update the versions in composer.json and run:

sbt "runMain codacy.codesniffer.docsgen.GeneratorMain"

This will create updated patterns.json, description.json and the individual documentation Markdown files.

CodeSniffer configuration file

PHP CodeSniffer can be configured by adding a phpcs.xml file to the source code.

Currently, the tool supports this configuration file except from one feature - setting installed_paths: <config name="installed_paths" />

Add new Codesniffer plugin

To add a new plugin to Codesniffer:

  1. Add the plugin dependency to require inside composer.json. This depedency must be available on Packagist

  2. Add to scala/codacy/codesniffer/docsgen/VersionsHelper.scala the plugin version:

    lazy val newPlugin = properties("pluginNamespace/pluginName").str
  3. Implement the plugin documentation parser inside scala/codacy/codesniffer/docsgen/parsers. The parser must extend DocsParser and override the following:

    Name Description
    override val repositoryURL Plugin's git repository
    override val checkoutCommit Commit related to the version on plugin's git repository (you can use the version tag for that)
    override val sniffRegex Regex to get all Sniffs implementation files
    override def patternIdPartsFor(relativizedFilePath: String): PatternIdParts Get the pattern id parts from pattern path
    override def descriptionWithDocs(rootDir: File, patternIdParts: PatternIdParts, patternFile: File): (Pattern.Description, Option[String]) Get tuple with small and extended description for pattern

    Example:

    class DrupalCoderDocsParser extends DocsParser {
    
        override val repositoryURL = "https://github.com/pfrenssen/coder.git"
    
        override val checkoutCommit: String = VersionsHelper.drupalCoder
    
        override val sniffRegex: Regex = """.*coder_sniffer\/(Drupal)\/Sniffs\/(.*?)\/(.*?)Sniff.php""".r
    
        override def patternIdPartsFor(relativizedFilePath: String): PatternIdParts = {
            val sniffRegex(drupalCoderVersion, sniffType, patternName) = relativizedFilePath
            PatternIdParts(drupalCoderVersion, sniffType, patternName)
        }
    
        override def descriptionWithDocs(rootDir: File,
                                        patternIdParts: PatternIdParts,
                                        patternFile: File): (Pattern.Description, Option[String]) = {
            (description(patternIdParts, rootDir), this.parseExtendedDescription("Drupal\\Sniffs", patternIdParts, rootDir))
        }
    
        private[this] def description(patternIdParts: PatternIdParts, rootDir: File): Pattern.Description = {
            val caseRegexPattern = """((?<=\p{Ll})\p{Lu}|\p{Lu}(?=\p{Ll}))""".r
            val patternName = caseRegexPattern.replaceAllIn(patternIdParts.patternName, " $1").trim
            val sniffName = caseRegexPattern.replaceAllIn(patternIdParts.sniffType, " $1").trim
            val title = Pattern.Title(s"$sniffName: $patternName")
            val extended = this.parseDescription("Drupal\\Sniffs", patternIdParts, rootDir)
            Pattern.Description(patternIdParts.patternId, title, extended, None, None)
        }
    
    }
  4. Add the new parser to the list of parsers inside scala/codacy/codesniffer/docsgen/Generator.scala.

    private[this] val parsers: List[DocsParser] = List(new PHPCSDocsParser(), ...)
  5. Generate the documentation

What is Codacy?

Codacy is an Automated Code Review Tool that monitors your technical debt, helps you improve your code quality, teaches best practices to your developers, and helps you save time in Code Reviews.

Among Codacy’s features

  • Identify new Static Analysis issues
  • Commit and Pull Request Analysis with GitHub, BitBucket/Stash, GitLab (and also direct git repositories)
  • Auto-comments on Commits and Pull Requests
  • Integrations with Slack, HipChat, Jira, YouTrack
  • Track issues in Code Style, Security, Error Proneness, Performance, Unused Code and other categories

Codacy also helps keep track of Code Coverage, Code Duplication, and Code Complexity.

Codacy supports PHP, Python, Ruby, Java, JavaScript, and Scala, among others.

Free for Open Source

Codacy is free for Open Source projects.

codacy-codesniffer-test2's People

Contributors

bmbferreira avatar caldasdeoliveira avatar cog avatar dependabot-preview[bot] avatar dependabot[bot] avatar dmarinhocodacy avatar dreigada avatar gjsduarte avatar goncalo-codacy avatar h314to avatar jllopes avatar josemiguelmelo avatar konecnyjakub avatar ljmf00 avatar lolgab avatar machadoit avatar mrfyda avatar pedrorijo91 avatar rtfpessoa avatar ruiteix avatar swlodarski avatar xplosunn avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.