Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PHPStan and other quality checks #185

Merged
merged 15 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
*.min.js
.git/
*.min.js
node_modules/
symbolic/
tmp/
vendor/
107 changes: 107 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: Automated tests

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:

tests:
# https://github.com/actions/virtual-environments
runs-on: ubuntu-22.04
defaults:
run:
working-directory: ./Extensions

steps:
- name: Git checkout source code
uses: actions/checkout@v4
with:
path: Extensions

# Composer tests

- name: Check PHP syntax
run: composer run-script php-lint

- name: Check PHTML syntax
run: composer run-script phtml-lint

- name: Use Composer cache
id: composer-cache
uses: actions/cache@v3
with:
path: Extensions/vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-

- name: Run Composer install
run: composer install --prefer-dist --no-progress
if: steps.composer-cache.outputs.cache-hit != 'true'

- name: PHP_CodeSniffer
run: composer run-script phpcs

- name: Git checkout FreshRSS source code
uses: actions/checkout@v4
with:
repository: FreshRSS/FreshRSS
path: FreshRSS

- name: PHPStan
run: composer run-script phpstan

- name: PHPStan Next Level
run: composer run-script phpstan-next

# NPM tests

- name: Uses Node.js
uses: actions/setup-node@v3
with:
# https://nodejs.org/en/about/releases/
node-version: '18'
cache: 'npm'
cache-dependency-path: 'Extensions/composer.lock'

- run: npm ci

- name: Check JavaScript syntax
run: npm run --silent eslint

- name: Check Markdown syntax
run: npm run --silent markdownlint

- name: Check CSS syntax
run: npm run --silent stylelint

- name: Check Right-to-left CSS
run: npm run --silent rtlcss && git diff --exit-code

# Shell tests

- name: Use shell cache
id: shell-cache
uses: actions/cache@v3
with:
path: Extensions/bin
key: ${{ runner.os }}[email protected]

- name: Add ./bin/ to $PATH
run: mkdir -p bin/ && echo "${PWD}/bin" >> $GITHUB_PATH

- name: Install typos
if: steps.shell-cache.outputs.cache-hit != 'true'
run: |
cd bin ;
wget -q 'https://github.com/crate-ci/typos/releases/download/v1.16.21/typos-v1.16.21-x86_64-unknown-linux-musl.tar.gz' &&
tar -xvf *.tar.gz './typos' &&
chmod +x typos &&
rm *.tar.gz ;
cd ..

- name: Check spelling
run: bin/typos
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
tmp
/node_modules/
.vscode/
bin/
node_modules/
symbolic/
tmp/
vendor/
2 changes: 2 additions & 0 deletions .jshintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.git/
node_modules/
symbolic/
tmp/
vendor/
5 changes: 5 additions & 0 deletions .markdownlintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.git/
node_modules/
symbolic/
tmp/
vendor/
2 changes: 2 additions & 0 deletions .stylelintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.git/
node_modules/
symbolic/
tmp/
vendor/
23 changes: 12 additions & 11 deletions .stylelintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,36 @@
"extends": "stylelint-config-recommended-scss",
"plugins": [
"stylelint-order",
"stylelint-scss"
"stylelint-scss",
"stylelint-stylistic"
],
"rules": {
"at-rule-empty-line-before": [
"always", {
"ignoreAtRules": [ "after-comment", "else" ]
}
],
"at-rule-name-space-after": [
"stylistic/at-rule-name-space-after": [
"always", {
"ignoreAtRules": [ "after-comment" ]
}
],
"block-closing-brace-newline-after": [
"stylistic/block-closing-brace-newline-after": [
"always", {
"ignoreAtRules": [ "if", "else" ]
}
],
"block-closing-brace-newline-before": "always-multi-line",
"block-opening-brace-newline-after": "always-multi-line",
"block-opening-brace-space-before": "always",
"color-hex-case": "lower",
"stylistic/block-closing-brace-newline-before": "always-multi-line",
"stylistic/block-opening-brace-newline-after": "always-multi-line",
"stylistic/block-opening-brace-space-before": "always",
"stylistic/color-hex-case": "lower",
"color-hex-length": "short",
"color-no-invalid-hex": true,
"declaration-colon-space-after": "always",
"declaration-colon-space-before": "never",
"indentation": "tab",
"stylistic/declaration-colon-space-after": "always",
"stylistic/declaration-colon-space-before": "never",
"stylistic/indentation": "tab",
"no-descending-specificity": null,
"no-eol-whitespace": true,
"stylistic/no-eol-whitespace": true,
"property-no-vendor-prefix": true,
"rule-empty-line-before": [
"always", {
Expand Down
23 changes: 23 additions & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[default.extend-identifiers]
ot = "ot"
Ths2 = "Ths2"

[default.extend-words]
referer = "referer"

[files]
extend-exclude = [
".git/",
"*.fr.md",
"*.map",
"*.min.js",
"*.rtl.css",
"*/i18n/de",
"*/i18n/fr",
"bin/",
"node_modules/",
"symbolic/",
"tmp/",
"vendor/",
"xExtension-ReadingTime/README.md"
]
68 changes: 68 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,71 @@ generate: ## Generate the extensions.json file
.PHONY: help
help:
@grep --extended-regexp '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

######################
## Tests and linter ##
######################
.PHONY: lint
lint: vendor/bin/phpcs ## Run the linter on the PHP files
$(PHP) vendor/bin/phpcs . -p -s

.PHONY: lint-fix
lint-fix: vendor/bin/phpcbf ## Fix the errors detected by the linter
$(PHP) vendor/bin/phpcbf . -p -s

bin/composer:
mkdir -p bin/
wget 'https://raw.githubusercontent.com/composer/getcomposer.org/a19025d6c0a1ff9fc1fac341128b2823193be462/web/installer' -O - -q | php -- --quiet --install-dir='./bin/' --filename='composer'

vendor/bin/phpcs: bin/composer
bin/composer install --prefer-dist --no-progress
ln -s ../vendor/bin/phpcs bin/phpcs

vendor/bin/phpcbf: bin/composer
bin/composer install --prefer-dist --no-progress
ln -s ../vendor/bin/phpcbf bin/phpcbf

bin/typos:
mkdir -p bin/
cd bin ; \
wget -q 'https://github.com/crate-ci/typos/releases/download/v1.16.21/typos-v1.16.21-x86_64-unknown-linux-musl.tar.gz' && \
tar -xvf *.tar.gz './typos' && \
chmod +x typos && \
rm *.tar.gz ; \
cd ..

node_modules/.bin/eslint:
npm install

node_modules/.bin/rtlcss:
npm install

vendor/bin/phpstan: bin/composer
bin/composer install --prefer-dist --no-progress

.PHONY: composer-test
composer-test: vendor/bin/phpstan
bin/composer run-script test

.PHONY: composer-fix
composer-fix:
bin/composer run-script fix

.PHONY: npm-test
npm-test: node_modules/.bin/eslint
npm test

.PHONY: npm-fix
npm-fix: node_modules/.bin/eslint
npm run fix

.PHONY: typos-test
typos-test: bin/typos
bin/typos

# TODO: Add shellcheck, shfmt, hadolint
.PHONY: test-all
test-all: composer-test npm-test typos-test

.PHONY: fix-all
fix-all: composer-fix npm-fix
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ There are some FreshRSS extensions out there, developed by community members:
* [Kagi Summarizer](https://code.sitosis.com/rudism/freshrss-kagi-summarizer): Adds a "Summarize" button to the top of all entries that will fetch the summary of the entry using the [Kagi Universal Summarizer](https://kagi.com/summarizer/index.html).


### By [@shinemoon](https://github.com/shinemoon]
### By [@shinemoon](https://github.com/shinemoon)

* [Colorful List](https://github.com/shinemoon/FreshRSS-Dev/tree/master/extensions/xExtension-ColorfulList): Generate light different background color for article list rows (relying on the feed name)

79 changes: 79 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"name": "freshrss.org/freshrss-extensions",
"description": "Extensions for FreshRSS",
"type": "project",
"homepage": "https://freshrss.org/",
"license": "AGPL-3.0",
"support": {
"docs": "https://freshrss.github.io/FreshRSS/",
"issues": "https://github.com/FreshRSS/Extensions/issues",
"source": "https://github.com/FreshRSS/Extensions/"
},
"keywords": [
"news",
"aggregator",
"RSS",
"Atom",
"WebSub"
],
"require": {
"php": ">=7.4",
"ext-ctype": "*",
"ext-curl": "*",
"ext-dom": "*",
"ext-fileinfo": "*",
"ext-gmp": "*",
"ext-intl": "*",
"ext-json": "*",
"ext-libxml": "*",
"ext-mbstring": "*",
"ext-openssl": "*",
"ext-pcre": "*",
"ext-pdo": "*",
"ext-pdo_sqlite": "*",
"ext-session": "*",
"ext-simplexml": "*",
"ext-xml": "*",
"ext-xmlreader": "*",
"ext-zend-opcache": "*",
"ext-zip": "*",
"ext-zlib": "*"
},
"suggest": {
"ext-iconv": "*",
"ext-pdo_mysql": "*",
"ext-pdo_pgsql": "*"
},
"require-dev": {
"php": ">=8.0",
"ext-phar": "*",
"ext-tokenizer": "*",
"ext-xmlwriter": "*",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-strict-rules": "^1.5",
"squizlabs/php_codesniffer": "^3.7"
},
"scripts": {
"php-lint": "find . -type d -name 'vendor' -prune -o -name '*.php' -print0 | xargs -0 -n1 -P4 php -l 1>/dev/null",
"phtml-lint": "find . -type d -name 'vendor' -prune -o -name '*.phtml' -print0 | xargs -0 -n1 -P4 php -l 1>/dev/null",
"phpcs": "phpcs . -s",
"phpcbf": "phpcbf . -p -s",
"phpstan": "phpstan analyse --memory-limit 512M .",
"phpstan-next": "phpstan analyse --level 9 --memory-limit 512M $(find . -type d -name 'vendor' -prune -o -name '*.php' -o -name '*.phtml' | grep -Fxvf ./tests/phpstan-next.txt | sort | paste -s -)",
"test": [
"@php-lint",
"@phtml-lint",
"@phpcs",
"@phpstan",
"@phpstan-next"
],
"fix": [
"@phpcbf"
]
},
"config": {
"allow-plugins": {
"phpstan/extension-installer": false
}
}
}
Loading