Skip to content

Commit d91b9f2

Browse files
authored
Merge pull request #983 from PHPCSStandards/phpcs-4.0/feature/sq-2448-remove-support-js-css
Remove CSS/JS support (HUGE PR, reviews welcome!)
2 parents cf5dd13 + 182f87a commit d91b9f2

File tree

327 files changed

+851
-18351
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

327 files changed

+851
-18351
lines changed

.cspell.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"dictionaries": ["php"],
44
"allowCompoundWords": true,
55
"ignorePaths": [
6-
"src/Standards/*/Tests/*/*.{inc,js,css}",
7-
"src/Standards/*/Tests/*/*.{inc,js,css}.fixed"
6+
"src/Standards/*/Tests/*/*.inc",
7+
"src/Standards/*/Tests/*/*.inc.fixed"
88
],
99
"ignoreRegExpList": ["email", "^\\s+\\*\\s+@(author|copyright)\\s+.*$"],
1010
"words": [
@@ -28,9 +28,7 @@
2828
"dnumber",
2929
"docblock",
3030
"encapsed",
31-
"gjslint",
3231
"groupid",
33-
"gsjlint",
3432
"hashbang",
3533
"heredoc",
3634
"hgblame",

.github/CONTRIBUTING.md

-2
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,6 @@ To help you with this, a number of convenience scripts are available:
265265
which will be placed in a `build/coverage-html` subdirectory.
266266
* `composer build` will build the phpcs.phar and phpcbf.phar files.
267267

268-
N.B.: You can ignore any skipped tests as these are for external tools.
269-
270268

271269
### Writing Tests
272270

.github/workflows/quicktest.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ concurrency:
2020
jobs:
2121
#### QUICK TEST ####
2222
# This is a much quicker test run which only runs the unit tests against the low/medium/high
23-
# supported PHP versions and skips the PHAR test and the tests for external JS/CSS tooling.
23+
# supported PHP versions and skips the PHAR test.
2424
# These are basically the same builds as in the Test->Coverage workflow, but then without doing
2525
# the code-coverage.
2626
quicktest:

.github/workflows/test.yml

-30
Original file line numberDiff line numberDiff line change
@@ -189,21 +189,6 @@ jobs:
189189
- name: "DEBUG: show libxml loaded version (php)"
190190
run: php -r 'echo "libxml loaded version = ", LIBXML_LOADED_VERSION, PHP_EOL;'
191191

192-
# This action also handles the caching of the dependencies.
193-
- name: Set up node
194-
if: ${{ matrix.custom_ini == false }}
195-
uses: actions/setup-node@v4
196-
with:
197-
node-version: '20'
198-
199-
- name: Install external tools used in tests
200-
if: ${{ matrix.custom_ini == false }}
201-
run: >
202-
npm install -g --fund false
203-
csslint
204-
eslint
205-
jshint
206-
207192
# Install dependencies and handle caching in one go.
208193
# @link https://github.com/marketplace/actions/install-php-dependencies-with-composer
209194
- name: Install Composer dependencies
@@ -291,21 +276,6 @@ jobs:
291276
ini-values: error_reporting=-1, display_errors=On${{ steps.set_ini.outputs.PHP_INI }}
292277
coverage: xdebug
293278

294-
# This action also handles the caching of the dependencies.
295-
- name: Set up node
296-
if: ${{ matrix.custom_ini == false }}
297-
uses: actions/setup-node@v4
298-
with:
299-
node-version: '20'
300-
301-
- name: Install external tools used in tests
302-
if: ${{ matrix.custom_ini == false }}
303-
run: >
304-
npm install -g --fund false
305-
csslint
306-
eslint
307-
jshint
308-
309279
# Install dependencies and handle caching in one go.
310280
# @link https://github.com/marketplace/actions/install-php-dependencies-with-composer
311281
- name: Install Composer dependencies

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
2121
## About
2222

23-
PHP_CodeSniffer is a set of two PHP scripts; the main `phpcs` script that tokenizes PHP, JavaScript and CSS files to detect violations of a defined coding standard, and a second `phpcbf` script to automatically correct coding standard violations. PHP_CodeSniffer is an essential development tool that ensures your code remains clean and consistent.
23+
PHP_CodeSniffer is a set of two PHP scripts; the main `phpcs` script that tokenizes PHP files to detect violations of a defined coding standard, and a second `phpcbf` script to automatically correct coding standard violations. PHP_CodeSniffer is an essential development tool that ensures your code remains clean and consistent.
2424

2525

2626
## Requirements

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "squizlabs/php_codesniffer",
3-
"description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.",
3+
"description": "PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.",
44
"license": "BSD-3-Clause",
55
"type": "library",
66
"keywords": [

phpcs.xml.dist

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
<file>src</file>
1010
<file>tests</file>
1111

12-
<exclude-pattern>*/src/Standards/*/Tests/*\.(inc|css|js)$</exclude-pattern>
13-
<exclude-pattern>*/tests/Core/*/*\.(inc|css|js)$</exclude-pattern>
12+
<exclude-pattern>*/src/Standards/*/Tests/*\.inc$</exclude-pattern>
13+
<exclude-pattern>*/tests/Core/*/*\.inc$</exclude-pattern>
1414
<exclude-pattern>*/tests/Core/*/Fixtures/*\.php$</exclude-pattern>
1515

1616
<arg name="basepath" value="."/>

src/Config.php

+13-12
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,11 @@
6464
* @property string $stdinPath The path to use for content passed on STDIN.
6565
* @property bool $trackTime Whether or not to track sniff run time.
6666
*
67-
* @property array<string, string> $extensions File extensions that should be checked, and what tokenizer to use.
67+
* @property array<string, string> $extensions File extensions that should be checked, and what tokenizer is used.
6868
* E.g., array('inc' => 'PHP');
69+
* Note: since PHPCS 4.0.0, the tokenizer used will always be 'PHP',
70+
* but the array format of the property has not been changed to prevent
71+
* breaking integrations which may be accessing this property.
6972
* @property array<string, string|null> $reports The reports to use for printing output after the run.
7073
* The format of the array is:
7174
* array(
@@ -545,8 +548,6 @@ public function restoreDefaults()
545548
$this->extensions = [
546549
'php' => 'PHP',
547550
'inc' => 'PHP',
548-
'js' => 'JS',
549-
'css' => 'CSS',
550551
];
551552
$this->sniffs = [];
552553
$this->exclude = [];
@@ -1146,19 +1147,19 @@ public function processLongArgument($arg, $pos)
11461147
if (empty($extensionsString) === false) {
11471148
$extensions = explode(',', $extensionsString);
11481149
foreach ($extensions as $ext) {
1149-
$slash = strpos($ext, '/');
1150-
if ($slash !== false) {
1150+
if (strpos($ext, '/') !== false) {
11511151
// They specified the tokenizer too.
11521152
list($ext, $tokenizer) = explode('/', $ext);
1153-
$newExtensions[$ext] = strtoupper($tokenizer);
1154-
continue;
1153+
if (strtoupper($tokenizer) !== 'PHP') {
1154+
$error = 'ERROR: Specifying the tokenizer to use for an extension is no longer supported.'.PHP_EOL;
1155+
$error .= 'PHP_CodeSniffer >= 4.0 only supports scanning PHP files.'.PHP_EOL;
1156+
$error .= 'Received: '.substr($arg, 11).PHP_EOL.PHP_EOL;
1157+
$error .= $this->printShortUsage(true);
1158+
throw new DeepExitException($error, 3);
1159+
}
11551160
}
11561161

1157-
if (isset($this->extensions[$ext]) === true) {
1158-
$newExtensions[$ext] = $this->extensions[$ext];
1159-
} else {
1160-
$newExtensions[$ext] = 'PHP';
1161-
}
1162+
$newExtensions[$ext] = 'PHP';
11621163
}
11631164
}
11641165

src/Files/File.php

+22-55
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHP_CodeSniffer\Exceptions\TokenizerException;
1515
use PHP_CodeSniffer\Fixer;
1616
use PHP_CodeSniffer\Ruleset;
17+
use PHP_CodeSniffer\Tokenizers\PHP;
1718
use PHP_CodeSniffer\Util\Common;
1819
use PHP_CodeSniffer\Util\Tokens;
1920

@@ -72,17 +73,10 @@ class File
7273
/**
7374
* The tokenizer being used for this file.
7475
*
75-
* @var \PHP_CodeSniffer\Tokenizers\Tokenizer
76+
* @var \PHP_CodeSniffer\Tokenizers\PHP
7677
*/
7778
public $tokenizer = null;
7879

79-
/**
80-
* The name of the tokenizer being used for this file.
81-
*
82-
* @var string
83-
*/
84-
public $tokenizerType = 'PHP';
85-
8680
/**
8781
* Was the file loaded from cache?
8882
*
@@ -240,15 +234,6 @@ public function __construct($path, Ruleset $ruleset, Config $config)
240234
$this->config = $config;
241235
$this->fixer = new Fixer();
242236

243-
$parts = explode('.', $path);
244-
$extension = array_pop($parts);
245-
if (isset($config->extensions[$extension]) === true) {
246-
$this->tokenizerType = $config->extensions[$extension];
247-
} else {
248-
// Revert to default.
249-
$this->tokenizerType = 'PHP';
250-
}
251-
252237
$this->configCache['cache'] = $this->config->cache;
253238
$this->configCache['sniffs'] = array_map('strtolower', $this->config->sniffs);
254239
$this->configCache['exclude'] = array_map('strtolower', $this->config->exclude);
@@ -412,14 +397,8 @@ public function process()
412397
continue;
413398
}
414399

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

419-
if (isset($listenerData['tokenizers'][$this->tokenizerType]) === false) {
420-
continue;
421-
}
422-
423402
if (trim($this->path, '\'"') !== 'STDIN') {
424403
// If the file path matches one of our ignore patterns, skip it.
425404
// While there is support for a type of each pattern
@@ -505,7 +484,7 @@ public function process()
505484
// We don't show this error for STDIN because we can't be sure the content
506485
// actually came directly from the user. It could be something like
507486
// refs from a Git pre-push hook.
508-
if ($foundCode === false && $this->tokenizerType === 'PHP' && $this->path !== 'STDIN') {
487+
if ($foundCode === false && $this->path !== 'STDIN') {
509488
$shortTags = (bool) ini_get('short_open_tag');
510489
if ($shortTags === false) {
511490
$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.';
@@ -543,14 +522,13 @@ public function parse()
543522
}
544523

545524
try {
546-
$tokenizerClass = 'PHP_CodeSniffer\Tokenizers\\'.$this->tokenizerType;
547-
$this->tokenizer = new $tokenizerClass($this->content, $this->config, $this->eolChar);
525+
$this->tokenizer = new PHP($this->content, $this->config, $this->eolChar);
548526
$this->tokens = $this->tokenizer->getTokens();
549527
} catch (TokenizerException $e) {
550528
$this->ignored = true;
551529
$this->addWarning($e->getMessage(), null, 'Internal.Tokenizer.Exception');
552530
if (PHP_CODESNIFFER_VERBOSITY > 0) {
553-
echo "[$this->tokenizerType => tokenizer error]... ";
531+
echo '[tokenizer error]... ';
554532
if (PHP_CODESNIFFER_VERBOSITY > 1) {
555533
echo PHP_EOL;
556534
}
@@ -582,7 +560,7 @@ public function parse()
582560
$numLines = $this->tokens[($this->numTokens - 1)]['line'];
583561
}
584562

585-
echo "[$this->tokenizerType => $this->numTokens tokens in $numLines lines]... ";
563+
echo "[$this->numTokens tokens in $numLines lines]... ";
586564
if (PHP_CODESNIFFER_VERBOSITY > 1) {
587565
echo PHP_EOL;
588566
}
@@ -1249,14 +1227,6 @@ public function getDeclarationName($stackPtr)
12491227
throw new RuntimeException('Token type "'.$this->tokens[$stackPtr]['type'].'" is not T_FUNCTION, T_CLASS, T_INTERFACE, T_TRAIT or T_ENUM');
12501228
}
12511229

1252-
if ($tokenCode === T_FUNCTION
1253-
&& strtolower($this->tokens[$stackPtr]['content']) !== 'function'
1254-
) {
1255-
// This is a function declared without the "function" keyword.
1256-
// So this token is the function name.
1257-
return $this->tokens[$stackPtr]['content'];
1258-
}
1259-
12601230
$stopPoint = $this->numTokens;
12611231
if (isset($this->tokens[$stackPtr]['parenthesis_opener']) === true) {
12621232
// For functions, stop searching at the parenthesis opener.
@@ -1637,22 +1607,20 @@ public function getMethodProperties($stackPtr)
16371607

16381608
if ($this->tokens[$stackPtr]['code'] === T_FUNCTION) {
16391609
$valid = [
1640-
T_PUBLIC => T_PUBLIC,
1641-
T_PRIVATE => T_PRIVATE,
1642-
T_PROTECTED => T_PROTECTED,
1643-
T_STATIC => T_STATIC,
1644-
T_FINAL => T_FINAL,
1645-
T_ABSTRACT => T_ABSTRACT,
1646-
T_WHITESPACE => T_WHITESPACE,
1647-
T_COMMENT => T_COMMENT,
1648-
T_DOC_COMMENT => T_DOC_COMMENT,
1610+
T_PUBLIC => T_PUBLIC,
1611+
T_PRIVATE => T_PRIVATE,
1612+
T_PROTECTED => T_PROTECTED,
1613+
T_STATIC => T_STATIC,
1614+
T_FINAL => T_FINAL,
1615+
T_ABSTRACT => T_ABSTRACT,
1616+
T_WHITESPACE => T_WHITESPACE,
1617+
T_COMMENT => T_COMMENT,
16491618
];
16501619
} else {
16511620
$valid = [
1652-
T_STATIC => T_STATIC,
1653-
T_WHITESPACE => T_WHITESPACE,
1654-
T_COMMENT => T_COMMENT,
1655-
T_DOC_COMMENT => T_DOC_COMMENT,
1621+
T_STATIC => T_STATIC,
1622+
T_WHITESPACE => T_WHITESPACE,
1623+
T_COMMENT => T_COMMENT,
16561624
];
16571625
}
16581626

@@ -2011,12 +1979,11 @@ public function getClassProperties($stackPtr)
20111979
}
20121980

20131981
$valid = [
2014-
T_FINAL => T_FINAL,
2015-
T_ABSTRACT => T_ABSTRACT,
2016-
T_READONLY => T_READONLY,
2017-
T_WHITESPACE => T_WHITESPACE,
2018-
T_COMMENT => T_COMMENT,
2019-
T_DOC_COMMENT => T_DOC_COMMENT,
1982+
T_FINAL => T_FINAL,
1983+
T_ABSTRACT => T_ABSTRACT,
1984+
T_READONLY => T_READONLY,
1985+
T_WHITESPACE => T_WHITESPACE,
1986+
T_COMMENT => T_COMMENT,
20201987
];
20211988

20221989
$isAbstract = false;

0 commit comments

Comments
 (0)