Skip to content

Commit

Permalink
Removed support for checking JS and CSS files (ref #2448)
Browse files Browse the repository at this point in the history
  • Loading branch information
gsherwood committed Jan 31, 2020
1 parent 91756a4 commit ea52e7b
Show file tree
Hide file tree
Showing 290 changed files with 875 additions and 16,802 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ The file documents changes to the PHP_CodeSniffer project.
## [Unreleased]

### Changes
- The `--extensions` command line argument no longer accepts the tokenizer along with the extension
- Previously, you would check `.module` files as PHP files using `--extensions=module/php`
- Now, you use `--extensions=module`
- Composer installs no longer include any test files

### Removed
- Support for checking the coding standards of JS files has been removed
- Support for checking the coding standards of CSS files has been removed
- Support for the deprecated `@codingStandard` annotation syntax has been removed
- Use the `phpcs:` or `@phpcs:` syntax instead
- Replace `@codingStandardsIgnoreFile` with `phpcs:ignoreFile`
Expand All @@ -20,3 +25,15 @@ The file documents changes to the PHP_CodeSniffer project.
- For example, `<element key="print" value="echo">`
- Removed the unused `T_ARRAY_HINT` token
- Removed the unused `T_RETURN_TYPE` token
- Removed sniff `Generic.Debug.ClosureLinter`
- Removed sniff `Generic.Debug.CSSLint`
- Removed sniff `Generic.Debug.ESLint`
- Removed sniff `Generic.Debug.JSHint`
- Removed sniff `Squiz.Classes.DuplicateProperty`
- Removed sniff `Squiz.Debug.JavaScriptLint`
- Removed sniff `Squiz.Debug.JSLint`
- Removed sniff `Squiz.Objects.DisallowObjectStringIndex`
- Removed sniff `Squiz.Objects.ObjectMemberComment`
- Removed sniff `Squiz.WhiteSpace.PropertyLabelSpacing`
- Removed the entire `Squiz.CSS` category, and sniffs within
- Removed the entire `MySource` standard, and all sniffs within
36 changes: 7 additions & 29 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ class Config
* string stdinContent Content passed directly to PHPCS on STDIN.
* string stdinPath The path to use for content passed on STDIN.
*
* array<string, string> extensions File extensions that should be checked, and what tokenizer to use.
* E.g., array('inc' => 'PHP');
* array<string, string> extensions File extensions that should be checked.
* E.g., array('php', 'inc');
* array<string, string|null> reports The reports to use for printing output after the run.
* The format of the array is:
* array(
Expand Down Expand Up @@ -477,10 +477,8 @@ public function restoreDefaults()
$this->tabWidth = 0;
$this->encoding = 'utf-8';
$this->extensions = [
'php' => 'PHP',
'inc' => 'PHP',
'js' => 'JS',
'css' => 'CSS',
'php',
'inc',
];
$this->sniffs = [];
$this->exclude = [];
Expand Down Expand Up @@ -1092,25 +1090,7 @@ public function processLongArgument($arg, $pos)
break;
}

$extensions = explode(',', substr($arg, 11));
$newExtensions = [];
foreach ($extensions as $ext) {
$slash = strpos($ext, '/');
if ($slash !== false) {
// They specified the tokenizer too.
list($ext, $tokenizer) = explode('/', $ext);
$newExtensions[$ext] = strtoupper($tokenizer);
continue;
}

if (isset($this->extensions[$ext]) === true) {
$newExtensions[$ext] = $this->extensions[$ext];
} else {
$newExtensions[$ext] = 'PHP';
}
}

$this->extensions = $newExtensions;
$this->extensions = explode(',', substr($arg, 11));
self::$overriddenDefaults['extensions'] = true;
} else if (substr($arg, 0, 7) === 'suffix=') {
if (isset(self::$overriddenDefaults['suffix']) === true) {
Expand Down Expand Up @@ -1381,8 +1361,7 @@ public function printPHPCSUsage()
echo ' <bootstrap> A comma separated list of files to run before processing begins'.PHP_EOL;
echo ' <encoding> The encoding of the files being checked (default is utf-8)'.PHP_EOL;
echo ' <extensions> A comma separated list of file extensions to check'.PHP_EOL;
echo ' The type of the file can be specified using: ext/type'.PHP_EOL;
echo ' e.g., module/php,es/js'.PHP_EOL;
echo ' e.g., php,inc,module'.PHP_EOL;
echo ' <file> One or more files and/or directories to check'.PHP_EOL;
echo ' <fileList> A file containing a list of files and/or directories to check (one per line)'.PHP_EOL;
echo ' <filter> Use either the "gitmodified" or "gitstaged" filter,'.PHP_EOL;
Expand Down Expand Up @@ -1443,8 +1422,7 @@ public function printPHPCBFUsage()
echo ' <bootstrap> A comma separated list of files to run before processing begins'.PHP_EOL;
echo ' <encoding> The encoding of the files being fixed (default is utf-8)'.PHP_EOL;
echo ' <extensions> A comma separated list of file extensions to fix'.PHP_EOL;
echo ' The type of the file can be specified using: ext/type'.PHP_EOL;
echo ' e.g., module/php,es/js'.PHP_EOL;
echo ' e.g., php,inc,module'.PHP_EOL;
echo ' <file> One or more files and/or directories to fix'.PHP_EOL;
echo ' <fileList> A file containing a list of files and/or directories to fix (one per line)'.PHP_EOL;
echo ' <filter> Use either the "gitmodified" or "gitstaged" filter,'.PHP_EOL;
Expand Down
37 changes: 7 additions & 30 deletions src/Files/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use PHP_CodeSniffer\Util;
use PHP_CodeSniffer\Exceptions\RuntimeException;
use PHP_CodeSniffer\Exceptions\TokenizerException;
use PHP_CodeSniffer\Tokenizers\PHP;

class File
{
Expand Down Expand Up @@ -71,17 +72,10 @@ class File
/**
* The tokenizer being used for this file.
*
* @var \PHP_CodeSniffer\Tokenizers\Tokenizer
* @var \PHP_CodeSniffer\Tokenizers\PHP
*/
public $tokenizer = null;

/**
* The name of the tokenizer being used for this file.
*
* @var string
*/
public $tokenizerType = 'PHP';

/**
* Was the file loaded from cache?
*
Expand Down Expand Up @@ -238,15 +232,6 @@ public function __construct($path, Ruleset $ruleset, Config $config)
$this->config = $config;
$this->fixer = new Fixer();

$parts = explode('.', $path);
$extension = array_pop($parts);
if (isset($config->extensions[$extension]) === true) {
$this->tokenizerType = $config->extensions[$extension];
} else {
// Revert to default.
$this->tokenizerType = 'PHP';
}

$this->configCache['cache'] = $this->config->cache;
$this->configCache['sniffs'] = array_map('strtolower', $this->config->sniffs);
$this->configCache['exclude'] = array_map('strtolower', $this->config->exclude);
Expand Down Expand Up @@ -406,17 +391,10 @@ public function process()
continue;
}

// Make sure this sniff supports the tokenizer
// we are currently using.
$class = $listenerData['class'];

if (isset($listenerData['tokenizers'][$this->tokenizerType]) === false) {
continue;
}

// If the file path matches one of our ignore patterns, skip it.
// While there is support for a type of each pattern
// (absolute or relative) we don't actually support it here.
$class = $listenerData['class'];
foreach ($listenerData['ignore'] as $pattern) {
// We assume a / directory separator, as do the exclude rules
// most developers write, so we need a special case for any system
Expand Down Expand Up @@ -492,7 +470,7 @@ public function process()
// We don't show this error for STDIN because we can't be sure the content
// actually came directly from the user. It could be something like
// refs from a Git pre-push hook.
if ($foundCode === false && $this->tokenizerType === 'PHP' && $this->path !== 'STDIN') {
if ($foundCode === false && $this->path !== 'STDIN') {
$shortTags = (bool) ini_get('short_open_tag');
if ($shortTags === false) {
$error = 'No PHP code was found in this file and short open tags are not allowed by this install of PHP. This file may be using short open tags but PHP does not allow them.';
Expand Down Expand Up @@ -531,14 +509,13 @@ public function parse()
}

try {
$tokenizerClass = 'PHP_CodeSniffer\Tokenizers\\'.$this->tokenizerType;
$this->tokenizer = new $tokenizerClass($this->content, $this->config, $this->eolChar);
$this->tokenizer = new PHP($this->content, $this->config, $this->eolChar);
$this->tokens = $this->tokenizer->getTokens();
} catch (TokenizerException $e) {
$this->ignored = true;
$this->addWarning($e->getMessage(), null, 'Internal.Tokenizer.Exception');
if (PHP_CODESNIFFER_VERBOSITY > 0) {
echo "[$this->tokenizerType => tokenizer error]... ";
echo "[tokenizer error]... ";
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo PHP_EOL;
}
Expand Down Expand Up @@ -570,7 +547,7 @@ public function parse()
$numLines = $this->tokens[($this->numTokens - 1)]['line'];
}

echo "[$this->tokenizerType => $this->numTokens tokens in $numLines lines]... ";
echo "[$this->numTokens tokens in $numLines lines]... ";
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo PHP_EOL;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Filters/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ protected function shouldProcessFile($path)
$extensions = [];
array_shift($fileParts);
foreach ($fileParts as $part) {
$extensions[implode('.', $fileParts)] = 1;
$extensions[] = implode('.', $fileParts);
array_shift($fileParts);
}

$matches = array_intersect_key($extensions, $this->config->extensions);
$matches = array_intersect($extensions, $this->config->extensions);
if (empty($matches) === true) {
return false;
}
Expand Down
19 changes: 4 additions & 15 deletions src/Ruleset.php
Original file line number Diff line number Diff line change
Expand Up @@ -1204,16 +1204,6 @@ public function populateTokenListeners()
}
}

$tokenizers = [];
$vars = get_class_vars($sniffClass);
if (isset($vars['supportedTokenizers']) === true) {
foreach ($vars['supportedTokenizers'] as $tokenizer) {
$tokenizers[$tokenizer] = $tokenizer;
}
} else {
$tokenizers = ['PHP' => 'PHP'];
}

$tokens = $this->sniffs[$sniffClass]->register();
if (is_array($tokens) === false) {
$msg = "Sniff $sniffClass register() method must return an array";
Expand Down Expand Up @@ -1249,11 +1239,10 @@ public function populateTokenListeners()

if (isset($this->tokenListeners[$token][$sniffClass]) === false) {
$this->tokenListeners[$token][$sniffClass] = [
'class' => $sniffClass,
'source' => $sniffCode,
'tokenizers' => $tokenizers,
'ignore' => $ignorePatterns,
'include' => $includePatterns,
'class' => $sniffClass,
'source' => $sniffCode,
'ignore' => $ignorePatterns,
'include' => $includePatterns,
];
}
}
Expand Down
19 changes: 0 additions & 19 deletions src/Standards/Generic/Docs/Debug/CSSLintStandard.xml

This file was deleted.

19 changes: 0 additions & 19 deletions src/Standards/Generic/Docs/Debug/ClosureLinterStandard.xml

This file was deleted.

19 changes: 0 additions & 19 deletions src/Standards/Generic/Docs/Debug/JSHintStandard.xml

This file was deleted.

10 changes: 0 additions & 10 deletions src/Standards/Generic/Sniffs/Commenting/DocCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,6 @@
class DocCommentSniff implements Sniff
{

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


/**
* Returns an array of tokens this test wants to listen for.
Expand Down
10 changes: 0 additions & 10 deletions src/Standards/Generic/Sniffs/Commenting/FixmeSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@
class FixmeSniff implements Sniff
{

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


/**
* Returns an array of tokens this test wants to listen for.
Expand Down
10 changes: 0 additions & 10 deletions src/Standards/Generic/Sniffs/Commenting/TodoSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@
class TodoSniff implements Sniff
{

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


/**
* Returns an array of tokens this test wants to listen for.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@
class InlineControlStructureSniff implements Sniff
{

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

/**
* If true, an error will be thrown; otherwise a warning.
*
Expand Down Expand Up @@ -95,21 +85,6 @@ public function process(File $phpcsFile, $stackPtr)
return;
}
}

// In Javascript DO WHILE loops without curly braces are legal. This
// is only valid if a single statement is present between the DO and
// the WHILE. We can detect this by checking only a single semicolon
// is present between them.
if ($tokens[$stackPtr]['code'] === T_WHILE && $phpcsFile->tokenizerType === 'JS') {
$lastDo = $phpcsFile->findPrevious(T_DO, ($stackPtr - 1));
$lastSemicolon = $phpcsFile->findPrevious(T_SEMICOLON, ($stackPtr - 1));
if ($lastDo !== false && $lastSemicolon !== false && $lastDo < $lastSemicolon) {
$precedingSemicolon = $phpcsFile->findPrevious(T_SEMICOLON, ($lastSemicolon - 1));
if ($precedingSemicolon === false || $precedingSemicolon < $lastDo) {
return;
}
}
}
}//end if

if (isset($tokens[$stackPtr]['parenthesis_opener'], $tokens[$stackPtr]['parenthesis_closer']) === false
Expand Down
Loading

0 comments on commit ea52e7b

Please sign in to comment.