Skip to content

Travis: Enforce phpcs line length + whitespace#3488

Merged
Alkarex merged 10 commits intoFreshRSS:masterfrom
Alkarex:travis-line-length
Feb 28, 2021
Merged

Travis: Enforce phpcs line length + whitespace#3488
Alkarex merged 10 commits intoFreshRSS:masterfrom
Alkarex:travis-line-length

Conversation

@Alkarex
Copy link
Copy Markdown
Member

@Alkarex Alkarex commented Feb 27, 2021

  • Give up on allowing a mixture of tabs and spaces, in order to be able to easily enforce line length and whitespace rules.
    See [CI] Add PHP 7.3 to Travis configuration #2317 (comment)

  • Report warnings in Travis, and not only errors

  • Lines longer than lineLimit=165 are reported as a warning (this is the size of a GitHub window)

  • Lines longer than absoluteLineLimit=190 are now an error (that works also for our .phtml template files)

  • Fixed the lines that did not comply with those rules. Mainly some lines that were much too long, but also a some wrong whitespace

  • Now also include our tests

  • Incidently, works also for our .css files

Now we can run:

phpcs -p --extensions=phtml,php,css .

My motivation came from giving a try to https://marketplace.visualstudio.com/items?itemName=ikappas.phpcs that provides instant feedback in the editor.
Before this patch, there were warnings all over the place.

@Alkarex Alkarex added this to the 1.18.0 milestone Feb 27, 2021
@Alkarex Alkarex requested a review from Frenzie February 27, 2021 11:53
@aledeg
Copy link
Copy Markdown
Member

aledeg commented Feb 27, 2021

* Give up on allowing a mixture of tabs and spaces, in order to be able to easily enforce line length and whitespace rules.
  See [#2317 (comment)](https://github.com/FreshRSS/FreshRSS/pull/2317#discussion_r583260405)

Yes 🎉

Copy link
Copy Markdown
Member

@aledeg aledeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am surprised that there is not more impacted files :)

Comment on lines 580 to +582
$sql .= ' AND `lastSeen` < (SELECT `lastSeen`'
. ' FROM (SELECT e2.`lastSeen` FROM `_entry` e2 WHERE e2.id_feed = :id_feed2'
. ' ORDER BY e2.`lastSeen` DESC LIMIT 1 OFFSET :keep_min) last_seen2)';
. ' FROM (SELECT e2.`lastSeen` FROM `_entry` e2 WHERE e2.id_feed = :id_feed2'
. ' ORDER BY e2.`lastSeen` DESC LIMIT 1 OFFSET :keep_min) last_seen2)';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you could use the NOWDOC notation.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be, but it is only a part of a longer string construction

Comment on lines +673 to +674
protected function sqlListEntriesWhere($alias = '', $filters = null, $state = FreshRSS_Entry::STATE_ALL,
$order = 'DESC', $firstId = '', $date_min = 0) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case like that, don't you think that having one argument per line is more readable?

protected function sqlListEntriesWhere(
	$alias = '',
	$filters = null,
	$state = FreshRSS_Entry::STATE_ALL,
	$order = 'DESC',
	$firstId = '',
	$date_min = 0
) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potentially yes for here, although I am not so found of excessive lines in general, as it generates more vertical scrolling, which reduces my ability to get the bigger picture of a piece of code.
In any case, the ambition of this PR (which is already large :-)) was just to fix the biggest problems - there is still room for improvement

FreshRSS_UserDAO::touch();
if (is_array($ids)) { //Many IDs at once (used by API)
if (true) { //Speed heuristics //TODO: Not implemented yet for SQLite (so always call IDs one by one)
//if (true) { //Speed heuristics //TODO: Not implemented yet for SQLite (so always call IDs one by one)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather remove it completely than having some commented code.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes indeed, but in this specific case, it is to match the construct of the parent code and make the TODO easier to understand & address:

if (count($ids) < 6) { //Speed heuristics

@Alkarex
Copy link
Copy Markdown
Member Author

Alkarex commented Feb 27, 2021

Here you are @aledeg c86067c

@Alkarex
Copy link
Copy Markdown
Member Author

Alkarex commented Feb 27, 2021

I realised that we can include .js files more completely 02add34

.PHONY: lint
lint: bin/phpcs ## Run the linter on the PHP files
$(PHP) ./bin/phpcs . --standard=phpcs.xml --warning-severity=0 --extensions=php -p
$(PHP) ./bin/phpcs . -p -s
Copy link
Copy Markdown
Member Author

@Alkarex Alkarex Feb 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aledeg Does that look good to you for the Makefile?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now file extensions are defined in phpcs.xml
-s is to include the name of broken rules in the outputs

@Alkarex Alkarex merged commit 947e918 into FreshRSS:master Feb 28, 2021
@Alkarex Alkarex deleted the travis-line-length branch February 28, 2021 11:26
Alkarex added a commit to Alkarex/FreshRSS that referenced this pull request Mar 2, 2022
Alkarex added a commit that referenced this pull request Mar 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants