lin3s/cs

The coding standards in the LIN3S way

v0.7.5 2018-10-30 08:03 UTC

README

The coding standards in the LIN3S way.

SensioLabsInsight Build Status Scrutinizer Code Quality Total Downloads      Latest Stable Version Latest Unstable Version

WHY?

This package is created to centralize all the checks style of LIN3S projects, in an easy way to install all the tools and improving the maintainability. It is a flexible and customizable solution to automatize all related with coding standards. This library is focused to PHP, Javascript and Sass projects.

  • Checks if Composer json has changes, the lock must be committed too.
  • Fixes the PHP code with fully customizable PHP-CS-Fixer.
  • Lints the Twig files with TwigCS.
  • Checks mess detections with PHPMD.
  • Checks the Sass best practices with Stylelint.
  • Checks the code quality of Javascript files with ESLint.

This library is very focused to use as pre-commit hook so, this is the reason of Git PHP class exists. The checkers only validate the files that they are going to commit.

Prerequisites

LIN3S's CS is a PHP console application so, it requires PHP itself. Apart of it, this library has the following requirements:

  1. Composer
$ curl -sS https://getcomposer.org/installer | php
  1. Node.js
$ npm install -g stylelint
$ npm install -g eslint     # >= v4.0.0
$ npm install -g eslint-plugin-class-property eslint-plugin-react eslint-plugin-babel babel-eslint

Getting started

The recommended and the most suitable way to install is through Composer. Be sure that the tool is installed in your system and execute the following command:

$ composer require lin3s/cs --dev

Then you have to update the composer.json with the following code:

"scripts": {
    "lin3scs-scripts": [
        "LIN3S\\CS\\Composer\\Hooks::buildDistFile",
        "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
        "LIN3S\\CS\\Composer\\Hooks::addHooks",
        "LIN3S\\CS\\Composer\\Hooks::addFiles"
    ]
},
"extra": {
    "incenteev-parameters": {
        "file": ".lin3s_cs.yml",
        "dist-file": ".lin3s_cs.yml.dist"
    },
    "scripts-dev": {
        "post-install-cmd": [
            "@lin3scs-scripts"
        ],
        "post-update-cmd": [
            "@lin3scs-scripts"
        ]
    }
}

REMEMBER: The .lin3s_cs.yml file is generated dynamically with Composer. The best practices recommend that only track the .dist file ignoring the .lin3s_cs.yml inside .gitignore. In the same way, we recommend that, also, dynamically generated .phpspec_cs, .php_cs, .stylelintrc.js, .eslintrc.js and .editorconfig files, it should be ignored.

Use ESLint in a React.js environment

In LIN3S are building a lot of projects with React.js so, keeping in mind the simplicity of the configuration process the following lin3s are our requirements to standardize the JS code inside this environment.

# .lin3s_cs.yml

parameters:

    # ...

    eslint_rules:
        plugins:
            # ...
            - react
        rules:
            react/display-name: off
            react/forbid-prop-types: off
            react/jsx-boolean-value: off
            react/jsx-closing-bracket-location: off
            react/jsx-curly-spacing: off
            react/jsx-indent-props: off
            react/jsx-max-props-per-line: off
            react/jsx-no-duplicate-props: error
            react/jsx-no-literals: off
            react/jsx-no-undef: error
            jsx-quotes: error
            react/jsx-sort-props: error
            react/jsx-uses-react: error
            react/jsx-uses-vars: error
            react/no-danger: error
            react/no-did-mount-set-state: error
            react/no-did-update-set-state: error
            react/no-direct-mutation-state: error
            react/no-set-state: off
            react/no-unknown-property: error
            react/prop-types: off
            react/react-in-jsx-scope: off
            react/require-extension: off
            react/self-closing-comp: off
            react/sort-comp: off
            react/sort-prop-types: error
            react/wrap-multilines: off

Licensing Options

License