Skip to content

Commit

Permalink
Merge pull request #326 from tighten/8.x
Browse files Browse the repository at this point in the history
8.0 release
  • Loading branch information
driftingly authored Jan 6, 2023
2 parents 2219e3c + 3ec8390 commit b56b662
Show file tree
Hide file tree
Showing 36 changed files with 108 additions and 2,382 deletions.
33 changes: 12 additions & 21 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ composer global require tightenco/tlint
composer global update tightenco/tlint
```

### 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.
Expand Down Expand Up @@ -146,7 +151,6 @@ class Preset implements PresetInterface
{
return [
CustomLinter::class,
ModelMethodOrder::class,
];
}

Expand Down Expand Up @@ -204,13 +208,10 @@ The default configuration is "tighten", but you may change this by adding a `tfo
| `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(). |
| `ModelMethodOrder` | Model method order should be: booting > boot > booted > custom_static > relationships > scopes > accessors > mutators > custom |
| `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. |
| `NoMethodVisibilityInTests` | There should be no method visibility in test methods. [ref](https://github.com/tighten/tlint/issues/106#issuecomment-537952774) |
| `NoParensEmptyInstantiations` | No parenthesis on empty instantiations |
| `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 |
Expand All @@ -219,44 +220,34 @@ The default configuration is "tighten", but you may change this by adding a `tfo
| `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 |
| `RestControllersMethodOrder` | REST methods in controllers should match the ordering here: https://laravel.com/docs/controllers#restful-partial-resource-routes |
| `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. |
| `ViewWithOverArrayParameters` | Prefer `view(...)->with(...)` over `view(..., [...])`. |
<!-- /linters -->

### General PHP

- `NoParensEmptyInstantiations`
- `OneLineBetweenClassVisibilityChanges`
- `QualifiedNamesOnlyForClassName`
- `RemoveLeadingSlashNamespaces`

### PHPUnit

- `NoMethodVisibilityInTests`

### Laravel

- `ApplyMiddlewareInRoutes`
- `ArrayParametersOverViewWith`
- `FullyQualifiedFacades`
- `MailableMethodsInBuild`
- `NoLeadingSlashesOnRoutePaths`
- `ModelMethodOrder`
- `NoDocBlocksForMigrationUpDown`
- `NoJsonDirective`
- `NoSpaceAfterBladeDirectives`, `SpaceAfterBladeDirectives`
- `PureRestControllers`
- `RequestHelperFunctionWherePossible`
- `RequestValidation`
- `RestControllersMethodOrder`
- `SpacesAroundBladeRenderContent`
- `UseAnonymousMigrations`
- `UseAuthHelperOverFacade`
- `ViewWithOverArrayParameters`

## Available Formatters (Beta)

Expand All @@ -273,14 +264,14 @@ The default configuration is "tighten", but you may change this by adding a `tfo
| `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. |
| `NoSpaceAfterBladeDirectives` | No space between blade template directive names and the opening parenthesis. |
| `RemoveLeadingSlashNamespaces` | Prefer `Namespace\...` over `\Namespace\...`. |
| `NoLeadingSlashesOnRoutePaths` | No leading slashes on route paths. |
| `RequestHelperFunctionWherePossible` | Use the request(...) helper function directly to access request values wherever possible. |
| `OneLineBetweenClassVisibilityChanges` | Class members of differing visibility must be separated by a blank line. |
| `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` | Puts a space between blade control structure names and the opening parenthesis |
| `SpacesAroundBladeRenderContent` | Spaces around blade rendered content. |
| `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. |
<!-- /formatters -->
Expand All @@ -297,8 +288,8 @@ The default configuration is "tighten", but you may change this by adding a `tfo
- `MailableMethodsInBuild`
- `NoDatesPropertyOnModels`
- `NoDocBlocksForMigrationUpDown`
- `NoSpaceAfterBladeDirectives`
- `NoLeadingSlashesOnRoutePaths`
- `NoSpaceAfterBladeDirectives`
- `RequestHelperFunctionWherePossible`
- `RequestValidation`
- `SpaceAfterBladeDirectives`
Expand Down
59 changes: 59 additions & 0 deletions src/AbstractBase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace Tighten\TLint;

use PhpParser\Node;

abstract class AbstractBase
{
public const DESCRIPTION = 'No Description.';

protected $description;
protected $filename;
protected $code;
protected $codeLines;

public function __construct($code, $filename = null)
{
$this->description = static::DESCRIPTION;
$this->filename = $filename;
$this->code = $code;
$this->codeLines = preg_split('/\r\n|\r|\n/', $code);
}

public static function appliesToPath(string $path, array $configPaths): bool
{
return true;
}

public function getFilename()
{
return $this->filename;
}

public function getCode(): string
{
return $this->code;
}

public function getCodeLines()
{
return $this->codeLines;
}

public function getCodeLine(int $line)
{
return $this->getCodeLines()[$line - 1];
}

public function getCodeLinesFromNode(Node $node)
{
return array_reduce(
range($node->getStartLine(), $node->getEndLine()),
function ($carry, $line) {
return $carry . $this->getCodeLine($line);
},
''
);
}
}
50 changes: 5 additions & 45 deletions src/BaseFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,63 +5,23 @@
use PhpParser\Lexer;
use PhpParser\Parser;

class BaseFormatter
class BaseFormatter extends AbstractBase
{
public const DESCRIPTION = 'No Description for Formatter.';

protected $description;
protected $filename;
protected $code;
protected $codeLines;

public function __construct($code, $filename = null)
{
$this->description = static::DESCRIPTION;
$this->filename = $filename;
$this->code = $code;
$this->codeLines = preg_split('/\r\n|\r|\n/', $code);
}

public static function appliesToPath(string $path, array $configPaths): bool
public function format(Parser $parser, Lexer $lexer): string
{
return true;
}

public function format(Parser $parser, Lexer $lexer)
{
return [];
return $this->code;
}

public function getFormatDescription()
public function getFormatDescription(): string
{
return $this->description;
}

public function setFormatDescription(string $description)
public function setFormatDescription(string $description): string
{
return $this->description = $description;
}

public function getFilename()
{
return $this->filename;
}

public function getCode(): string
{
return $this->code;
}

public function getCodeLines()
{
return $this->codeLines;
}

public function getCodeLine(int $line)
{
return $this->getCodeLines()[$line - 1];
}

public function replaceCodeLine(int $line, string $replacement): string
{
$this->codeLines[$line - 1] = $replacement;
Expand Down
54 changes: 1 addition & 53 deletions src/BaseLinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,12 @@

use Closure;
use LogicException;
use PhpParser\Node;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitor\FindingVisitor;
use PhpParser\Parser;

class BaseLinter
class BaseLinter extends AbstractBase
{
public const DESCRIPTION = 'No Description for Linter.';

protected $description;
protected $filename;
protected $code;
protected $codeLines;

public function __construct($code, $filename = null)
{
$this->description = static::DESCRIPTION;
$this->filename = $filename;
$this->code = $code;
$this->codeLines = preg_split('/\r\n|\r|\n/', $code);
}

public static function appliesToPath(string $path, array $configPaths): bool
{
return true;
}

public function lint(Parser $parser)
{
return $this->traverseAutomatically($parser);
Expand All @@ -46,37 +25,6 @@ public function setLintDescription(string $description)
return $this->description = $description;
}

public function getFilename()
{
return $this->filename;
}

public function getCode(): string
{
return $this->code;
}

public function getCodeLines()
{
return $this->codeLines;
}

public function getCodeLine(int $line)
{
return $this->getCodeLines()[$line - 1];
}

public function getCodeLinesFromNode(Node $node)
{
return array_reduce(
range($node->getStartLine(), $node->getEndLine()),
function ($carry, $line) {
return $carry . $this->getCodeLine($line);
},
''
);
}

protected function visitor(): Closure
{
throw new LogicException('Custom linters must override either the `lint` or `visitor` method.');
Expand Down
Loading

0 comments on commit b56b662

Please sign in to comment.