Skip to content

Commit 3cc3c27

Browse files
committed
feat: supports CSS properties from W3C and MDN
Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
1 parent 3c1abcb commit 3cc3c27

25 files changed

+1297
-11631
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ nbproject/
33
vendor
44
tools/vendor
55
**/composer.lock
6+
**/.cache
67
**/tests/.phpunit.result.cache
78
**/build/
89
# From tools/cache/.gitignore

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
/vendor
33
/tools/vendor
44
composer.lock
5+
.cache
56
tests/.phpunit.result.cache
67
build/

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ IMAGE="${PROJECT_NAME}:${PHP_VERSION}"
99
help:
1010
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
1111

12-
setup: build-php install ## Initialize project
12+
setup: build-php install test-load-fixtures ## Initialize project
1313

1414
build-php: ## Build PHP image
1515
@echo "Build php ${PHP_VERSION}"
@@ -30,6 +30,9 @@ test: ## Execute tests for given PHP version
3030
test-update: ## Execute tests and update snapshots for given PHP version
3131
@$(call run-php,composer test:update-snapshot $(filter-out $@,$(MAKECMDGOALS)))
3232

33+
test-load-fixtures: ## Execute tests and load fixtures for given PHP version
34+
@$(call run-php,composer test:load-fixtures $(filter-out $@,$(MAKECMDGOALS)))
35+
3336
lint: ## Execute lint for given PHP version
3437
@$(call run-php,composer php-cs-fixer $(filter-out $@,$(MAKECMDGOALS)))
3538

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
[![License](https://poser.pugx.org/neilime/php-css-lint/license)](https://packagist.org/packages/neilime/php-css-lint)
1010
[![Sponsor](https://img.shields.io/badge/%E2%9D%A4-Sponsor-ff69b4)](https://github.com/sponsors/neilime)
1111

12-
📢 **Php CSS Lint** is a php script that lint css files and strings:
12+
📢 **Php CSS Lint** is a php script that lint css files and strings.
13+
It supports [W3C](https://www.w3.org/Style/CSS/) and [MDN](https://developer.mozilla.org/en-US/docs/Web/CSS) CSS specifications.
1314

1415
```
1516
===========================================================

composer.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,14 @@
2727
"ext-json": "*"
2828
},
2929
"require-dev": {
30+
"guzzlehttp/guzzle": "^7.9",
3031
"mikey179/vfsstream": "^1.6",
3132
"pcov/clobber": "^2.0",
32-
"phpunit/phpunit": "^9.5.27"
33+
"phpunit/phpunit": "^9.5.27",
34+
"symfony/cache": "^7.2",
35+
"symfony/console": "^7.2",
36+
"symfony/css-selector": "^7.2",
37+
"symfony/dom-crawler": "^7.2"
3338
},
3439
"autoload": {
3540
"psr-4": {
@@ -38,14 +43,16 @@
3843
},
3944
"autoload-dev": {
4045
"psr-4": {
41-
"TestSuite\\": "tests/TestSuite"
46+
"Tests\\Fixtures\\": "tests/Fixtures",
47+
"Tests\\TestSuite\\": "tests/TestSuite"
4248
}
4349
},
4450
"bin": [
4551
"scripts/php-css-lint"
4652
],
4753
"scripts": {
4854
"test": "phpunit --colors --configuration tests/phpunit.xml",
55+
"test:load-fixtures": "php scripts/css-referential-scraper && php scripts/css-popular-downloader",
4956
"test:ci": "@test -d pcov.enabled=1 -d max_execution_time=0 --coverage-text --coverage-clover ./build/logs/clover.xml --coverage-html ./build/coverage/",
5057
"php-cs-fixer": "@php-cs-fixer:fix --dry-run",
5158
"php-cs-fixer:fix": "tools/vendor/bin/php-cs-fixer fix --show-progress=dots --diff --config=.php-cs-fixer.dist.php",

scripts/css-popular-downloader

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
require __DIR__ . '/../vendor/autoload.php';
5+
6+
use Tests\Fixtures\Downloader\CssFileDownloader;
7+
8+
$downloader = new CssFileDownloader();
9+
$downloader->downloadLatestFiles(__DIR__ . '/../tests/fixtures');
10+
11+
echo "Done.\n";

scripts/css-referential-generator

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
require __DIR__ . '/../vendor/autoload.php';
5+
6+
function saveDataset(string $className, array $referential): void
7+
{
8+
$datasetClass = new ReflectionClass($className);
9+
$datasetFile = $datasetClass->getFileName();
10+
11+
$referentialString = var_export($referential, true);
12+
$referentialString = str_replace('array (', '[', $referentialString);
13+
$referentialString = str_replace(')', ']', $referentialString);
14+
15+
$datasetFileContent = file_get_contents($datasetFile);
16+
$datasetFileContent = preg_replace(
17+
'/public static array \$referential = \[.*?\];/s',
18+
'public static array $referential = ' . $referentialString . ';',
19+
$datasetFileContent
20+
);
21+
22+
file_put_contents($datasetFile, $datasetFileContent);
23+
}
24+
25+
$cssPropertiesFile = __DIR__ . '/../tests/fixtures/css-properties.json';
26+
$cssProperties = json_decode(file_get_contents($cssPropertiesFile), true);
27+
28+
$standardsProperties = [];
29+
$nonStandardsProperties = [];
30+
31+
foreach ($cssProperties as $propertyName => $property) {
32+
$isStandard = $property['standard'] ?? false;
33+
if ($isStandard) {
34+
$standardsProperties[$propertyName] = true;
35+
} else {
36+
$nonStandardsProperties[$propertyName] = true;
37+
}
38+
}
39+
40+
// Add missing non-standard properties
41+
$missingNonStandardsProperties = [
42+
'-webkit-overflow-scrolling',
43+
'-webkit-margin-end',
44+
'-moz-osx-font-smoothing',
45+
];
46+
foreach ($missingNonStandardsProperties as $propertyName) {
47+
if (isset($standardsProperties[$propertyName]) || isset($nonStandardsProperties[$propertyName])) {
48+
throw new Exception("Property $propertyName already exists in either standards or non-standards properties.");
49+
}
50+
$nonStandardsProperties[$propertyName] = true;
51+
}
52+
53+
ksort($standardsProperties);
54+
ksort($nonStandardsProperties);
55+
saveDataset(CssLint\Referential\StandardPropertiesReferential::class, $standardsProperties);
56+
saveDataset(CssLint\Referential\NonStandardPropertiesReferential::class, $nonStandardsProperties);

scripts/css-referential-scraper

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
require __DIR__ . '/../vendor/autoload.php';
5+
6+
use Tests\Fixtures\Downloader\CssReferentialScraper;
7+
8+
$forceRefresh = in_array('--force-refresh', $argv);
9+
10+
$scraper = new CssReferentialScraper($forceRefresh);
11+
12+
echo "Fetching CSS property list...\n";
13+
$referentials = $scraper->fetchReferentials();
14+
15+
echo "Fetched " . count($referentials['properties']) . " properties\n";
16+
$cssPropertiesFile = __DIR__ . '/../tests/fixtures/css-properties.json';
17+
$scraper->saveToJson($referentials['properties'], $cssPropertiesFile);
18+
echo "Saved to {$cssPropertiesFile}\n";
19+
20+
echo "Done.\n";

src/CssLint/Linter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ protected function lintSelectorChar(string $charValue): ?bool
335335
// Wildcard and hash
336336
if (in_array($charValue, ['*', '#'], true)) {
337337
$selector = $this->getContextContent();
338-
if ($selector === '' || $selector === '0' || preg_match('/[a-zA-Z>,\'"] *$/', $selector)) {
338+
if ($selector === '' || $selector === '0' || preg_match('/[a-zA-Z>+,\'"] *$/', $selector)) {
339339
$this->addContextContent($charValue);
340340
return true;
341341
}

0 commit comments

Comments
 (0)