• Stars
    star
    517
  • Rank 85,558 (Top 2 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 7 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Tighten linter for Laravel conventions.

TLint Logo


Latest Version on Packagist

Install (Requires PHP 8.1+)

Note TLint is intended to work with the tools included in Duster. To receive the best coverage we recommend using Duster to install and configure TLint.

# Include in project
composer require tightenco/tlint --dev

# Include globally
composer global require tightenco/tlint

Upgrade

# Upgrade in project
composer update tightenco/tlint

#Upgrade globally
composer global update tightenco/tlint

Upgrading from 8.x to 9.x

TLint 9 requires PHP >= 8.1.

tformat.json has been dropped in favor of a single tlint.json file.

Now linting the following files and directories:

  • public/
  • bootstrap/
  • server.php
  • app/Http/Middleware/RedirectIfAuthenticated.php
  • Exceptions/Handler.php
  • app/Http/Controllers/Auth/
  • app/Http/Kernel.php

To continue excluding these files and directories add them to your tlint.json file under excluded.

Upgrading from 7.x to 8.x

A significant number of formatters were added between the 7.x and 8.x releases. If you want to roll these out gradually or disable them altogether, you can use the disabled setting in your tlint.json config.

Upgrading from 6.x to 7.x

TLint focuses on linting and formatting issues other tools are not able to catch. The 7.x release removes lints and formatters covered by tools in Duster. If you need to add these back you can grab them from an earlier version of TLint and follow the Custom Configuration documentation.

What Is It?

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.

Usage

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 lint --only=ArrayParametersOverViewWith

Example Output

Linting TestLaravelApp/routes/web.php
============
Lints:
============
! Prefer `view(...)->with(...)` over `view(..., [...])`.
5 : `    return view('test', ['test' => 'test']);``

Formatting

Using the same conventions as above, but using the format command, you can auto-fix some lints:

tlint format

Linting Configuration

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. You may disable linting for specific directories by adding them to the "excluded" list. You may provide custom paths by adding them to the "paths" lists.

{
    "preset": "laravel",
    "disabled": ["ArrayParametersOverViewWith"],
    "excluded": ["tests/"],
    "paths": [
        {
            "controllers": ["app/Domain/Http/Controllers"]
        }
    ]
}

Custom Configuration & Presets

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 Tighten\TLint\Presets\PresetInterface;

class Preset implements PresetInterface
{
  public function getLinters() : array
  {
    return [
      CustomLinter::class,
    ];
  }

  public function getFormatters() : array
  {
    return [
        CustomFormatter::class,
    ];
  }
}

Then your config could look like:

{
    "preset": "App\\Support\\Linting\\Preset"
}

This lets you define custom linting/formatting functionality, or modify the existing linters/formatters to your liking.

Editor Integrations

PHPStorm

Sublime

VSCode

Available Linters

Linter Description
ApplyMiddlewareInRoutes Apply middleware in routes (not controllers).
ArrayParametersOverViewWith Prefer view(..., [...]) over view(...)->with(...).
FullyQualifiedFacades Import facades using their full namespace.
MailableMethodsInBuild Mailable values (from and subject etc) should be set in build().
NoDatesPropertyOnModels The $dates property was deprecated in Laravel 8. Use $casts instead.
NoDocBlocksForMigrationUpDown Remove doc blocks from the up and down method in migrations.
NoJsonDirective Use blade {{ $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) !!}">
NoLeadingSlashesOnRoutePaths No leading slashes on route paths.
NoRequestAll No request()->all(). Use request()->only(...) to retrieve specific input values.
NoSpaceAfterBladeDirectives No space between blade template directive names and the opening paren:@section ( -> @section(
OneLineBetweenClassVisibilityChanges Class members of differing visibility must be separated by a blank line
PureRestControllers You should not mix restful and non-restful public methods in a controller
QualifiedNamesOnlyForClassName Fully Qualified Class Names should only be used for accessing class names
RemoveLeadingSlashNamespaces Prefer Namespace\... over \Namespace\....
RequestHelperFunctionWherePossible Use the request(...) helper function directly to access request values wherever possible
RequestValidation Use request()->validate(...) helper function or extract a FormRequest instead of using $this->validate(...) in controllers
SpaceAfterBladeDirectives Put a space between blade control structure names and the opening paren:@if( -> @if (
SpacesAroundBladeRenderContent Spaces around blade rendered content:{{1 + 1}} -> {{ 1 + 1 }}
UseAnonymousMigrations Prefer anonymous class migrations.
UseAuthHelperOverFacade Prefer the auth() helper function over the Auth Facade.

General PHP

  • OneLineBetweenClassVisibilityChanges
  • QualifiedNamesOnlyForClassName
  • RemoveLeadingSlashNamespaces

Laravel

  • ApplyMiddlewareInRoutes
  • ArrayParametersOverViewWith
  • FullyQualifiedFacades
  • MailableMethodsInBuild
  • NoLeadingSlashesOnRoutePaths
  • NoDocBlocksForMigrationUpDown
  • NoJsonDirective
  • NoSpaceAfterBladeDirectives, SpaceAfterBladeDirectives
  • PureRestControllers
  • RequestHelperFunctionWherePossible
  • RequestValidation
  • SpacesAroundBladeRenderContent
  • UseAnonymousMigrations
  • UseAuthHelperOverFacade

Available Formatters

Notes about formatting

  • Formatting is designed to alter the least amount of code possible.
  • Import related formatters are not designed to alter grouped imports.
Formatter Description
ArrayParametersOverViewWith Prefer view(..., [...]) over view(...)->with(...).
FullyQualifiedFacades Import facades using their full namespace.
MailableMethodsInBuild Mailable values (from and subject etc) should be set in build().
NoDatesPropertyOnModels Use $casts instead of $dates on Eloquent models.
NoDocBlocksForMigrationUpDown Removes doc blocks from the up and down method in migrations.
NoLeadingSlashesOnRoutePaths No leading slashes on route paths.
NoSpaceAfterBladeDirectives No space between blade template directive names and the opening paren:@section ( -> @section(
OneLineBetweenClassVisibilityChanges Class members of differing visibility must be separated by a blank line
RemoveLeadingSlashNamespaces Prefer Namespace\... over \Namespace\....
RequestHelperFunctionWherePossible Use the request(...) helper function directly to access request values wherever possible
RequestValidation Use request()->validate(...) helper function or extract a FormRequest instead of using $this->validate(...) in controllers
SpaceAfterBladeDirectives Put a space between blade control structure names and the opening paren:@if( -> @if (
SpacesAroundBladeRenderContent Spaces around blade rendered content:{{1 + 1}} -> {{ 1 + 1 }}
UseAnonymousMigrations Prefer anonymous class migrations.
UseAuthHelperOverFacade Prefer the auth() helper function over the Auth Facade.

General PHP

  • OneLineBetweenClassVisibilityChanges
  • RemoveLeadingSlashNamespaces

Laravel

  • ArrayParametersOverViewWith
  • FullyQualifiedFacades
  • MailableMethodsInBuild
  • NoDatesPropertyOnModels
  • NoDocBlocksForMigrationUpDown
  • NoLeadingSlashesOnRoutePaths
  • NoSpaceAfterBladeDirectives
  • RequestHelperFunctionWherePossible
  • RequestValidation
  • SpaceAfterBladeDirectives
  • SpacesAroundBladeRenderContent
  • UseAnonymousMigrations
  • UseAuthHelperOverFacade

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

More Repositories

1

ziggy

Use your Laravel routes in JavaScript.
JavaScript
3,816
star
2

jigsaw

Simple static sites with Laravel’s Blade.
PHP
2,115
star
3

takeout

Docker-based development-only dependency manager. macOS, Linux, and WSL2-only and installs via PHP's Composer... for now.
PHP
1,590
star
4

collect

A Collections-only split from Laravel's Illuminate Support
PHP
1,506
star
5

parental

Use single table inheritance in your Laravel app
PHP
1,327
star
6

mailthief

A fake mailer for Laravel Applications for testing mail.
PHP
685
star
7

lambo

Quick new application creation with Laravel and Valet
PHP
612
star
8

duster

Automatic configuration for Laravel apps to apply Tighten's standard linting & code standards.
PHP
409
star
9

novapackages

PHP
334
star
10

quicksand

Easily schedule regular cleanup of old soft-deleted Eloquent data.
PHP
294
star
11

gistlog

GistLog - simple, easy blogging based on GitHub gists
CSS
274
star
12

symposium

Management of proposals, bios, photos, etc. for conference speakers.
PHP
177
star
13

nova-google-analytics

Google Analytics integration with Laravel Nova
PHP
161
star
14

onramp

Easing the onramp for new or non-PHP developers to become Laravel devs.
PHP
157
star
15

overload

Method overloading in PHP
PHP
115
star
16

nova-stripe

Easily show information about Stripe charges and balances in your Nova dashboard
JavaScript
103
star
17

giscus

Notifications for Gist Comments
PHP
103
star
18

laravelversions

PHP
94
star
19

jigsaw-blog-template

Starter template for a blog, using Jigsaw by Tighten
Blade
91
star
20

confomo

ConFOMO is a simple tool that makes it easy to track your friends at conferences.
JavaScript
74
star
21

ozzie

Open source project monitor for Tighten
PHP
56
star
22

nova-package-development

A forum for talking about the process of Nova Package Development
52
star
23

jigsaw-docs-template

Starter template for a documentation site, using Jigsaw by Tighten
Blade
44
star
24

craft-build-query

A plugin for Craft CMS, demonstrating how to build complex or optimized queries by modifying an ElementCriteriaModel.
PHP
39
star
25

liftoff

A quick start for Laravel development in a new environment
Shell
38
star
26

builtwithjigsaw

A list of sites built with Jigsaw
Blade
35
star
27

react-gif-search-engine

React GIF Search Engine
JavaScript
33
star
28

react-gif-search-engine-old

JavaScript
32
star
29

jigsaw-site

Jigsaw Documentation Site
Blade
30
star
30

blink-my-lights

Quick proof-of-concept for flashing/blinking lights with Laravel and IFTTT
PHP
26
star
31

laravelm1

Tracking what works and doesn't in the Laravel ecosystem on M1
Blade
25
star
32

configs

Standard config files for Tighten projects
PHP
24
star
33

built-with-laravel

Real organizations and companies building with Laravel.
PHP
24
star
34

nova-releases

A package to provide a card and a tool giving information about Nova releases, including whether you're current
Vue
20
star
35

consoles

Quick shortcut list to API developer consoles
PHP
19
star
36

json-api-examples

Implementing JSON:API in laravel
18
star
37

laravel-react-demo

Demo of how to include React components in a Laravel project with Elixir
PHP
17
star
38

laravel-mix-jigsaw

Laravel Mix plugin for Jigsaw.
JavaScript
16
star
39

nova-package-discovery

Nova card for showing stats from novapackages.com
PHP
16
star
40

simplecast-php

Simplecast PHP SDK
PHP
15
star
41

php-package-skeleton

Tighten's PHP Package skeleton -- inspired by & some source from spatie/skeleton-php
Shell
15
star
42

checkmate

Check the version of all your Laravel apps and notify if they're out of date
PHP
14
star
43

tighten-coding-standard

A PHP Code_Sniffer configuration for Tighten's coding standard.
PHP
14
star
44

saasaas

SaaSaaS - create your next "AirBnB for ___" idea
PHP
14
star
45

laravel-elixir-webpack-react

A package to provide support for compiling React JSX files in Laravel Elixir 6
JavaScript
13
star
46

podcast-subscriber

Easy podcast subscriber app
PHP
10
star
47

laravel-mix-react

Easy alternative Laravel Mix configuration for projects using React
JavaScript
10
star
48

laravel-preset-jest

Front-end presets that include Jest for React and Vue
PHP
9
star
49

laraveldrivers

List all third-party Laravel drivers
PHP
9
star
50

blade-style-guide

"PSR-Blade"--style guide for Laravel Blade
9
star
51

easy-embeddable-polls

easy-static-polls
Vue
8
star
52

valet-fallback

Fallback web site for Valet
PHP
8
star
53

phpreleases-action

GitHub action that integrates with the PHP Releases API.
7
star
54

dev-battle-1-react

Tighten Co. Senior Dev Battle - React app
PHP
7
star
55

dev-battle-1-vue

Tighten Co. Senior Dev Battle - Vue app[
JavaScript
6
star
56

duster-action

Dockerfile
6
star
57

react-native-time-input

A simple time input component with autoformatting.
TypeScript
6
star
58

jigsaw-collections-demo

CSS
5
star
59

tlint-plugin

TLint PHPStorm Plugin
Kotlin
4
star
60

gif-gif-vue

Samantha Geitz Jest testing in Vue Laracon talk
PHP
4
star
61

hyperspoon

Lua
4
star
62

gif-gif-react

React version of Samantha Geitz's Jest Testing Laracon talk
PHP
4
star
63

postit

PHP
3
star
64

laravel-elixir-elm

JavaScript
3
star
65

pickr-api

PHP
3
star
66

laravel-tricks

Laravel Tricks rewrite
PHP
3
star
67

tallstack

The new web site for tallstack.dev
PHP
2
star
68

jazz

JavaScript-inspired development utilities
PHP
2
star
69

nova-tighten-themes

Tighten's Nova Themes
CSS
2
star
70

learnwebdevelopment

LearnWebDevelopment.org
CSS
2
star
71

tlint-sublime-plugin

tlint-sublime-plugin
Python
2
star
72

intro-to-react

Intro to React workshop given by Samantha Geitz at PeersConf 2018
JavaScript
2
star
73

omgphp

OMGPHP.com
CSS
1
star
74

borsh-php

1
star
75

phpreleases

API endpoints with support information for PHP major/minor versions and releases 5.6 and later
PHP
1
star
76

pickr-nativescript

NativeScript version of Pickr for Tighten Dev Battle 2
CSS
1
star
77

automation-scripts

Lua
1
star
78

pickr-reactnative

JavaScript
1
star
79

mon-petit

PHP
1
star
80

whyphp

CSS
1
star
81

laravelstar

Vue
1
star
82

dev-battle-landing

Landing page for the Tighten Dev Battle
PHP
1
star