Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.
/ readable Public archive

A static analysis tool for PHP with a focus on code readability

License

Notifications You must be signed in to change notification settings

officient/readable

Repository files navigation

readable

PHP code analyzer, similar to eslint, but with a focus on readability. The idea is to build an analyzer that can guarantee long term code maintainability for a project. The main project values are extendibility, ease of use, speed of analysis and simplicity.

quick links: Rules and default configuration

codecov

Codeship Status for officient/readable

Installation and Usage

You can install readable using npm:

$ npm install @officient/readable --save-dev

You can get the help on usage:

$ npx readable --help

You should then set up a configuration file:

$ npx readable --init

After that, you can run readable on any file or directory like this:

$ npx readable

You can also add it to your NPM scripts:

"scripts": {
    "test": "readable"
},
 $ npm run test

Also you can use our docker-image:

$ docker run --rm \
    -v "$(pwd):/rootfs:ro" \
    --user "$(id -u):$(id -g)" \
    -w /rootfs \
    officient/readable:latest

Exit code

0
No errors
1
Found errors
2
Unexpected behaviour

Configuration

After running readable --init, you'll have a .readable.json file in your directory. In it, you'll see some rules configured like this:

{
  "paths": [
    "src/",
    "!src/vendor/"
  ],
  "rules": {}
}

Start a path with ! to ignore the folder.

Baseline

If you have a bunch of errors and you don't want to fix them all at once, readable can ignore errors in existing code, while ensuring that new code doesn't have errors:

$ npx readable --save-base-line .baseline.json

will generate or update .baseline.json file containing the current errors. Add "baseline" param to your .readable.json:

{
  "baseline": ".baseline.json",
  "..."
}

You can commit the changes so that readable running in other places (e.g. CI) won't complain about those errors. If you want to see all errors run with --disable-base-line flag:

$ npx readable --disable-base-line

Rules

See Rules and default configuration for default rules. Or read how to create a custom rule.

Development

To lint code run:

npm run lint

To fix lint:

$ npm run fix

To test:

$ npm run test

To update api docs:

$ npm run docs

While developing you can update to latest master with

$ npm install @officient/readable@latest