Commit c31df23e authored by Pieter Frenssen's avatar Pieter Frenssen Committed by Klaus Purer
Browse files

fix(TxtFileLineLength): Long Markdown links may exceed line length...

fix(TxtFileLineLength): Long Markdown links may exceed line length restrictions (#2867863 by pfrenssen)
parent f04a5501
Loading
Loading
Loading
Loading
+26 −15
Original line number Diff line number Diff line
@@ -55,13 +55,23 @@ class TxtFileLineLengthSniff implements Sniff

            $content    = rtrim($tokens[$stackPtr]['content']);
            $lineLength = mb_strlen($content, 'UTF-8');
            // Lines without spaces are allowed to be longer (for example long URLs).
            if ($lineLength > 80) {
                // Often text files contain long URLs that need to be preceded
                // with certain textual elements that are significant for
                // preserving the formatting of the document - e.g. a long link
                // in a bulleted list. If we find that the line does not contain
                // any spaces after the 40th character we'll allow it.
                if (preg_match('/\s+/', mb_substr($content, 40)) === 0) {
                    return;
                }

                // Lines without spaces are allowed to be longer.
                // Markdown allowed to be longer for lines
                // - without spaces
                // - starting with #
            // - containing URLs (https://)
            // - starting with | (tables).
            if ($lineLength > 80 && preg_match('/^([^ ]+$|#|.*https?:\/\/|\|)/', $content) === 0) {
                // - starting with | (tables)
                // - containing a link.
                if (preg_match('/^([^ ]+$|#|\||.*\[.+\]\(.+\))/', $content) === 0) {
                    $data    = [
                        80,
                        $lineLength,
@@ -69,7 +79,8 @@ class TxtFileLineLengthSniff implements Sniff
                    $warning = 'Line exceeds %s characters; contains %s characters';
                    $phpcsFile->addWarning($warning, $stackPtr, 'TooLong', $data);
                }
        }
            }//end if
        }//end if

    }//end process()

+7 −0
Original line number Diff line number Diff line
@@ -3,6 +3,13 @@
Some long build status icon:
[![Build Status](https://travis-ci.org/FreelyGive/decoupled_auth.png)](https://travis-ci.org/FreelyGive/decoupled_auth)

A link in a bulleted list:

* [Documentation](./docs/version/1.0.0-rc1/format/markdown/user-documentation/how-to-use.md)

A long internal [reference style link][reflink]:
[reflink]: ./docs/version/1.0.0-rc1/format/markdown/user-documentation/how-to-use.md

| First Header  | Second Header | First Header  | Second Header | First Header  | Second Header |
| ------------- | ------------- | ------------- | ------------- | ------------- | ------------- |
| Content Cell  | Content Cell  | Content Cell  | Content Cell  | Content Cell  | Content Cell  |