Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
......@@ -55,21 +55,32 @@ 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).
// 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) {
$data = [
80,
$lineLength,
];
$warning = 'Line exceeds %s characters; contains %s characters';
$phpcsFile->addWarning($warning, $stackPtr, 'TooLong', $data);
}
}
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 #
// - starting with | (tables)
// - containing a link.
if (preg_match('/^([^ ]+$|#|\||.*\[.+\]\(.+\))/', $content) === 0) {
$data = [
80,
$lineLength,
];
$warning = 'Line exceeds %s characters; contains %s characters';
$phpcsFile->addWarning($warning, $stackPtr, 'TooLong', $data);
}
}//end if
}//end if
}//end process()
......
......@@ -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 |
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment