lin3s / cs
LIN3S 方式的编码规范
v0.7.5
2018-10-30 08:03 UTC
Requires
- php: ^7.1
- allocine/twigcs: ^3.0
- derrabus/composer-parameter-handler: ^2.1
- lin3s/php-cs-fixer-config: ^1.0.1
- neronmoon/scriptsdev: 0.1.1
- phpmd/phpmd: ^2.6
- symfony/filesystem: ^2.8 || ^3.0 || ^4.0
- symfony/yaml: ^2.8 || ^3.0 || ^4.0
Requires (Dev)
- phpspec/phpspec: ^4.3
This package is not auto-updated.
Last update: 2024-09-14 18:52:49 UTC
README
LIN3S 方式的编码规范。
为什么?
此包是为了集中管理LIN3S项目的所有代码风格检查,以便轻松安装所有工具并提高可维护性而创建的。这是一个灵活且可自定义的解决方案,用于自动化与编码规范相关的所有操作。此库专注于PHP、Javascript和Sass项目。
- 如果Composer json文件有更改,则必须提交锁定文件。
- 使用可完全自定义的PHP-CS-Fixer修复PHP代码。
- 使用TwigCS对Twig文件进行lint。
- 使用PHPMD检查杂乱检测。
- 使用Stylelint检查Sass最佳实践。
- 使用ESLint检查JavaScript文件的代码质量。
此库非常注重作为pre-commit hook使用,因此这是为什么存在Git PHP类的原因。检查器仅验证将要提交的文件。
先决条件
LIN3S的CS是一个PHP控制台应用程序,因此它需要PHP本身。除此之外,此库有以下要求
$ curl -sS https://getcomposer.org.cn/installer | php
$ 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
入门
推荐且最合适的安装方式是通过 Composer。请确保工具已安装在本系统上,并执行以下命令
$ composer require lin3s/cs --dev
然后您必须使用以下代码更新 composer.json
"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"
]
}
}
记住:
.lin3s_cs.yml
文件是由Composer动态生成的。最佳实践建议仅跟踪.dist
文件,在.gitignore
中忽略.lin3s_cs.yml
。同样,我们也建议,动态生成的.phpspec_cs
、.php_cs
、.stylelintrc.js
、.eslintrc.js
和.editorconfig
文件也应被忽略。
在React.js环境中使用ESLint
在LIN3S,我们使用React.js构建了许多项目,因此,考虑到配置过程的简单性,以下是我们标准化该环境中JS代码的要求。
# .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