Coder Social home page Coder Social logo

hippo's People

Contributors

grahamcampbell avatar jbrooksuk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

hippo's Issues

Refactor reporters

In order to make reporters testable without hassle, we should refactor reporters to use FileSystem. The FileSystem could be then stubbed in the tests, without resorting to dealing with real files nor output capturing. CLIReporter could use FileSystem to put its output in a meta-file php://output and still work as expected.

Better getSyntaxTree method

Returning from CheckContext@getSyntaxTree is a PhpParser\Parser class, which isn't very useful as it doesn't allow traversing of the tree nodes.

This should be improved so that the return is a custom class extending from traverser which checks can implement.

Checks

We'll obviously need to add the checks themselves. For now we should focus on PSR standards as these are the better standards to have.

Basically, everything under PSR should be able to be checked for. We should be able to create a basic PSR check then have the other standards extend from them, de-duplicating a lot of code.

Following list uses this syntax to describe possible configuration options, with the assumption that the check is enabled. I.e. something like space/no character means that user can set it to either space, or no character, and the "no character" option will throw errors if it finds a space.

Style

  • Bitwise operators - &&/and
  • Prefer quote type
  • elseif vs else if
  • Dead code
  • Ban merged declarations, e.g. no $a = $b = 5; (be careful around for loops)
  • Ban multiple expressions per line, e.g. no $a = 5; $b = 6; (be careful around lambdas and default parameters)
  • Use fully qualified names in use statements
  • Include namespace in the file
  • Check for opening <?php or <? or <?=
  • Ban <?
  • Ban <?=
  • Check if the file contains only class/trait/interface/function declarations, or does it include some code as well
  • Braces are aligned across multiple lines
  • Enforce either short array syntax, or array()
  • Constants must be in uppercase.
  • PHP constants true, false, and null should be in lowercase.
  • Don't leave catch block empty.
  • Strict equality check.
  • Private names should begin with _

PHPdoc

  • List of mandatory fields
  • List of prohibited fields
  • List of types that are required to have PHPdoc
    • Class
    • Interface
    • Trait
    • Public method
    • Protected method
    • Private method
    • Function (be careful not to enforce this for lambdas)
    • File...? Anything else?
  • The same list, but this time of types that are banned to have PHPdoc

Whitespace

  • Ban trailing whitespace
  • Indentation style - spaces (how many?), tabs, or check for consistency only.
  • Line endings - \n, \r or \r\n, or check for consistency only.
  • Spaces after control structures - space/no character.
  • Spaces around operators - space/no character. (I'm almost sure we need finer control over types of operators here)
  • Spaces within for loop after ; (can it be merged to any other check?)
  • Whitespace around { and }
    • Behavior: newline/space/no character
    • Support for:
      • if
      • for
      • foreach
      • do
      • while
      • else (be careful, } else { might behave different from the rest. This suggests that configuration should to be aware of each keyword separately...)
      • switch
      • class/interface/trait
      • function (be careful around lambdas)
      • anything else?
  • Indent code under switch yes/no

File

  • Files must be in a certain encoding. PSR-1 uses UTF-8 without BOM.
  • No side affects.
  • Namespaces must follow PSR-0/PSR-4.

Multiple errors when no file exists

When you run ./hippo foo it'll error explaining that foo isn't a file, however the same warning is printed twice, but worded differently.

$ ./hippo foo
File not found: File does not exist: foo

Hippo interface

We need to create an interface to lay out the API to how Hippo should be accessed. HippoTextUI is fine, but only useful for CLI, so how do you access Hippo within your own project? It's pretty cumbersome.

Add reporter tests

Every reporter should be tested while having in mind following:

  • Avoid using just assertNotEmpty, because such tests doesn't do much
  • Use assertEquals, comparing the actual output to some expected output
  • Use FileSystem mock/stub (see #13)

These reporters need testing:

  • CLI
  • Array
  • Checkstyle (#22)

AbstractCheckTestCase

We need an abstract check test case for testing the checks themselves.

In regards to a test for BitwiseCheck:

all you need is create dummy File with two &&, run a check on it (like CheckRunner does -- perhaps add some protected utility methods to AbstractCheckTestCase?) and check in an assertion for two violations

Add support for CLI arguments

Following options should be configurable with CLI:

  • Which reporter to use, and where to put the output report
  • Verbose/quiet (alias to log levels)
  • Log levels (see #16)
  • Strict mode (see #16)
  • Easier way to get an argument (see comments below)

Global installation

Having hippo as a command accessible globally would be neat. I'm not sure how to do this though since composer.json already includes the bin values.

Implement XMLReporter

XMLReporter is currently not implemented. We should either remove it or implement it.

I'm not sure what CheckstyleReporter is for - I mean, it serializes into XML, so how is it different from XMLReporter?

If these two are going to do the same, only one should stay.

Token list needs rewinding for each check

Checks seem to inherit the token list position, so sometimes you need to rewind the iterator before you can start checking the code.

My feeling is that each check should be passed the token list iterator from the beginning.

HHVM tests has failed

The HHVM tests have failed for some reason; https://travis-ci.org/HippoPHP/Hippo/jobs/39542616

1) Hippo\Tests\FileTest::testGetLinesVaryingEol
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array (
     0 => '<?php echo 1;\n'
     1 => 'echo 2
+    echo 3
     '
-    2 => 'echo 3\n'
-    3 => ''
+    2 => false
 )
/home/travis/build/HippoPHP/Hippo/tests/Hippo/Tests/FileTest.php:59

Ignoring rules

How can I specify I don't care about:

(info) : Prefer single quotes to double

and

(error) : Line is too long.

And ignore them.

Better tokenization

Tokenizer.php is currently dependent on token_get_all which doesn't support the custom tokens we'll need for checks.

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.