mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-08-05 08:07:33 +02:00
Created Maximum line length (markdown)
53
Maximum-line-length.md
Normal file
53
Maximum-line-length.md
Normal file
@@ -0,0 +1,53 @@
|
||||
One line of code should have no more than **80 characters** (soft limit) and must never exceed **120 characters** (hard limit).
|
||||
|
||||
_Notice_: Travis-CI enforces the hard limit of 120 characters. Maintainers may ask you to indent lines longer than 80 characters before merging. This is generally done to keep the code as readable and maintainable as possible.
|
||||
|
||||
For long conditional statements, consider indenting the statement into multiple lines.
|
||||
|
||||
<details><summary>Example</summary><div><br>
|
||||
|
||||
**Bad** (the total length of the line is **94** characters)
|
||||
|
||||
```PHP
|
||||
if($time !== false && (time() - $duration < $time) && (!defined('DEBUG') || DEBUG !== true)) {
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
**Good** (add line breaks)
|
||||
|
||||
```PHP
|
||||
if($time !== false
|
||||
&& (time() - $duration < $time)
|
||||
&& (!defined('DEBUG') || DEBUG !== true)) {
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
</div></details><br>
|
||||
|
||||
For long text, either add line feeds, or make use of the [`heredoc`](http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc) syntax.
|
||||
|
||||
<details><summary>Example</summary><div><br>
|
||||
|
||||
**Bad** (the total length of the line is **340** characters - from [Lorem Ipsum](https://www.lipsum.com/feed/html))
|
||||
|
||||
```PHP
|
||||
$longtext = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse condimentum nec est eget posuere. Proin at sagittis risus. Fusce faucibus lectus leo, eu ornare velit tristique eu. Curabitur elementum facilisis ultricies. Praesent dictum fermentum lectus a rhoncus. Donec vitae justo metus. Sed molestie faucibus egestas.';
|
||||
```
|
||||
|
||||
**Good** (use `heredoc` syntax - this will add line-breaks)
|
||||
|
||||
```PHP
|
||||
$longtext = <<<EOD
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse
|
||||
condimentum nec est eget posuere. Proin at sagittis risus. Fusce faucibus
|
||||
lectus leo, eu ornare velit tristique eu. Curabitur elementum facilisis
|
||||
ultricies. Praesent dictum fermentum lectus a rhoncus. Donec vitae justo metus.
|
||||
Sed molestie faucibus egestas.
|
||||
EOD;
|
||||
```
|
||||
|
||||
</div></details><br>
|
||||
|
||||
_Reference_: [`Generic.Files.LineLength`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Generic/Sniffs/Files/LineLengthSniff.php)
|
Reference in New Issue
Block a user