Skip to content

Commit

Permalink
Merge branch 'release/0.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
lgnap committed Oct 4, 2017
2 parents 4058eb5 + 2fcf4d6 commit 4438fe8
Show file tree
Hide file tree
Showing 13 changed files with 288 additions and 116 deletions.
5 changes: 5 additions & 0 deletions .buildpath
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<buildpath>
<buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/>
<buildpathentry kind="src" path="vendor/composer">
<attributes>
<attribute name="composer" value="vendor"/>
</attributes>
</buildpathentry>
</buildpath>
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# IDE relatives
/.idea/

# Composer
/vendor/
composer.lock
composer.lock
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ vendor/bin/phpcs --standard=standard/Kamelot/ruleset.xml --extensions=php \
--encoding=utf-8 -n tests/Kamelot/ok/ --colors
```

Default ussage
Default usage
```bash
vendor/bin/phpcs --standard=standard/Kamelot/ruleset.xml --extensions=php \
--encoding=utf-8 -n src --colors
```

## Testing code

Run commands
### Run commands

Checking if everything is wrong :-)

Expand All @@ -35,18 +35,18 @@ vendor/bin/phpcs --standard=standard/Kamelot/ruleset.xml \
--extensions=php --encoding=utf-8 -n tests/Kamelot/ok
```

### PhpUnit
You can do that through phpunit now

## Installation
```bash
vendor/bin/phpunit
```

Installation in a Composer project (method 1)


Add the following lines to the require-dev section of your composer.json file.

"require-dev": {
"squizlabs/php_codesniffer": "^2.2 || ^3.0.2",
"moosh-be/CodeSniffer": "*"
},
"prefer-stable" : true
## Installation

Installation through Composer

composer require kamelot/CodeSniffer
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
}
},
"name" : "kamelot/code-sniffer",
"description" : "Ruleset for phpcodesniffer\n\nC'est mon premier package composer.\nC'est mon premier gitflow.\nC'est mon premier Ruleset.\n\nTout feedback est bien venu",
"license": "LGPL-3.0",

"description" : "Ruleset for phpcodesniffer. C'est mon premier package composer. C'est mon premier gitflow. C'est mon premier Ruleset. Tout feedback est bien venu",
"license" : "LGPL-3.0",
"require" : {
"squizlabs/php_codesniffer" : "3.1.0",
"php" : ">=7.0"
Expand All @@ -24,5 +23,8 @@
"email" : "[email protected]",
"role" : "Developper"
}
]
],
"require-dev": {
"phpunit/phpunit": "^6.3"
}
}
20 changes: 20 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.3/phpunit.xsd"
bootstrap="tests/autoload.php"
forceCoversAnnotation="true"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
verbose="true">

<testsuite name="Full tests">
<directory suffix="Test.php">tests</directory>
</testsuite>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
133 changes: 133 additions & 0 deletions src/standard/Kamelot/Sniffs/Commenting/TodoSniff.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?php
/**
* Generic_Sniffs_Commenting_TodoSniff.
*
* PHP version 5
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <[email protected]>
* @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
* @link http://pear.php.net/package/PHP_CodeSniffer
*/

namespace Standards\Sniffs\Comments;

use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Util\Tokens;

/**
* Based on Generic_Sniffs_Commenting_TodoSniff.
*
* Warns about TO DO comments.
*
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <[email protected]>
* @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
* @version Release: @package_version@
* @link http://pear.php.net/package/PHP_CodeSniffer
*/

class TodoSniff implements Sniff
{

/**
* A list of tokenizers this sniff supports.
*
* @var array
*/
public $supportedTokenizers = array(
'PHP',
'JS',
);


/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return Tokens::$commentTokens;

}//end register()


/**
* Processes this sniff, when one of its tokens is encountered.
*
* @param File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token in the stack passed in $tokens.
*
* @return int
*/
public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();

$foundComments = [];
$stackEnable = false;
$blockCommentStack = [];
foreach($tokens as $token) {
$code = $token['code'];
$line = $token['line'];
$content = $token['content'];

//search inline comment
if ($code === T_COMMENT && !$stackEnable) {
$foundComments[$line] = $content;
}


//search block comments
if ($code === T_DOC_COMMENT_OPEN_TAG) {
$stackEnable = true;
continue;
}

if ($code === T_DOC_COMMENT_CLOSE_TAG) {
$foundComments[$line] = join('', $blockCommentStack);
$blockCommentStack = [];
$stackEnable = false;
}

if ($stackEnable) {
$blockCommentStack[] = $content;
}
}

foreach ($foundComments as $lineNumber => $foundComment) {
$this->handleComment($phpcsFile, $lineNumber - 1, $foundComment);
}

return count($tokens) + 1;
}

private function handleComment(File $phpcsFile, $lineNumber, $foundComment)
{
if (preg_match('/(?:\A|[^\p{L}]+)todo([^\p{L}]+(.*)|\Z)/ui', $foundComment, $matches)) {
if (! preg_match('/WWW([a-z])*-([0-9])*/ui', $matches[1], $jiramatches)) {
// Clear whitespace and some common characters not required at
// the end of a to-do message to make the warning more informative.

$type = 'CommentFound';
$todoMessage = trim($matches[1]);
$todoMessage = trim($todoMessage, '-:[](). ');
$error = "Ajoutez l'id du ticket jira lié à ce TODO ";
$data = array($todoMessage);
if ($todoMessage !== '') {
$type = 'TaskFound';
$error .= ' "%s"';
}

$phpcsFile->addWarning($error, $lineNumber, $type, $data);
}
}

}
}//end class
File renamed without changes.
96 changes: 0 additions & 96 deletions standard/Kamelot/Sniffs/Commenting/TodoSniff.php

This file was deleted.

Loading

0 comments on commit 4438fe8

Please sign in to comment.