Package Data | |
---|---|
Maintainer Username: | loganhenson |
Maintainer Contact: | logan@loganhenson.com (Logan Henson) |
Package Create Date: | 2017-04-21 |
Package Last Update: | 2024-10-09 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-15 15:23:51 |
Package Statistics | |
---|---|
Total Downloads: | 885,561 |
Monthly Downloads: | 18,177 |
Daily Downloads: | 635 |
Total Stars: | 523 |
Total Watchers: | 15 |
Total Forks: | 32 |
Total Open Issues: | 3 |
composer global require tightenco/tlint
This is an opinionated code linter (with growing support for auto-formatting!) for Tighten flavored code conventions for Laravel and PHP.
For example, Laravel has many available ways to pass variables from a controller to a view:
A)
$value = 'Hello, World!';
return view('view', compact('value'));
B)
return view('view', ['value' => 'Hello, World!']);
C)
return view('view')
->with('value', 'Hello, World!');
In this case TLint will warn if you are not using the B) method. This example is a sort of "meta layer" of code linting, allowing teams to avoid higher level sticking points of code review / discussions.
TLint also has more immediately useful lints that can supplement your editor/IDE such as:
NoUnusedImports
TrailingCommasOnArrays
For entire project (you must pass the lint command to use other options)
tlint
For individual files and specific directories
tlint lint index.php
tlint lint app
You can also lint only diff files by running the following with unstaged git changes
tlint lint --diff
tlint lint src --diff
Want the output from a file as JSON? (Primarily used for integration with editor plugins)
tlint lint test.php --json
Want to only run a single linter?
tlint --only=UseConfigOverEnv
Linting TestLaravelApp/routes/web.php
============
Lints:
============
! Prefer `view(...)->with(...)` over `view(..., [...])`.
5 : ` return view('test', ['test' => 'test']);``
Using the same conventions as above, but using the format command, you can auto-fix some lints:
tlint format
TLint Ships with 2 "preset" styles: Laravel & Tighten. The Laravel preset is intended to match the conventions agreed upon by the Laravel framework contributors, while the Tighten preset is intended to match those agreed upon by Tighten team members.
The default configuration is "tighten" flavored, but you may change this by adding a tlint.json
file to your project's root directory with the following schema:
You may further customize the linters used by adding specific lint names to the
"disabled"
list (As shown below). You may disable linting for specific directories by adding them to the"excluded"
list (As shown below).
{
"preset": "laravel",
"disabled": ["NoInlineVarDocs"],
"excluded": [
"tests/"
]
}
You can also add your own custom preset and linters by providing a fully-qualified class name as the preset. For example, if you created a custom preset class:
namespace App\Support\Linting;
/** use ... */
class Preset implements PresetInterface
{
public function getLinters() : array
{
return [
PrefixTestsWithTest::class,
ModelMethodOrder::class,
];
}
public function getFormatters() : array
{
return [];
}
}
Then your config could look like:
{
"preset": "App\\Support\\Linting\\Preset",
}
This lets you define whatever custom linting functionality, or modify the existing linters to your liking.
RemoveLeadingSlashNamespaces
QualifiedNamesOnlyForClassName
ClassThingsOrder
AlphabeticalImports
TrailingCommasOnArrays
NoParensEmptyInstantiations
SpaceAfterSoleNotOperator
OneLineBetweenClassVisibilityChanges
NoStringInterpolationWithoutBraces
ConcatenationSpacing
NewLineAtEndOfFile
NoInlineVarDocs
(https://github.com/tightenco/tlint/issues/108)NoUnusedImports
NoMethodVisibilityInTests
(https://github.com/tightenco/tlint/issues/106#issuecomment-537952774)ViewWithOverArrayParameters
view(..., [...])
over view(...)->with(...)
. ArrayParametersOverViewWith
UseConfigOverEnv
PureRestControllers
RestControllersMethodOrder
request(...)
wherever possible. RequestHelperFunctionWherePossible
UseAuthHelperOverFacade
NoDocBlocksForMigrationUpDown
ImportFacades
MailableMethodsInBuild
NoLeadingSlashesOnRoutePaths
ApplyMiddlewareInRoutes
ModelMethodOrder
dd()
NoDd
request()->validate(...)
helper function or extract a FormRequest instead of using $this->validate(...)
in controllers RequestValidation
NoSpaceAfterBladeDirectives
, SpaceAfterBladeDirectives
SpacesAroundBladeRenderContent
{{ $model }}
auto escaping for models, and double quotes via json_encode over @json blade directive: <vue-comp :values='@json($var)'>
-> <vue-comp :values="{{ $model }}">
OR <vue-comp :values="{{ json_encode($var) }}">
NoJsonDirective
AlphabeticalImports
UnusedImports
ExcessSpaceBetweenAndAfterImports