Coding standards for file ending newlines

Dave Reid - October 12, 2008 - 01:21
Project:Coder
Version:7.x-1.x-dev
Component:Review/Rules
Category:task
Priority:minor
Assigned:Unassigned
Status:needs work
Issue tags:Novice
Description

After a discussion in #drupal, decided to be consistant with trailing newlines in core files. Going to do a search-replace for '\W+\Z' in core and get a patch up.

#1

webchick - February 9, 2009 - 04:03

#2

Dave Reid - February 11, 2009 - 01:50
Assigned to:Dave Reid» Anonymous

#3

chx - February 11, 2009 - 03:09
Status:active» won't fix

you will get a "no ending newline" from patch if that's missing imo... it does no harm and sometimes you need to fight your editor to not add one.

#4

Dave Reid - February 11, 2009 - 03:27
Title:Coding standards - remove ending newlines» Coding standards for file ending newlines
Status:won't fix» active

Maybe we should consider making sure all core files have an ending newline? Getting the no ending newline patch warning is something that might confuse novices and make them think they had done something wrong (like I had for a while when I first started patching core).

If not, feel free to mark as won't fix again.

#5

JamesAn - April 6, 2009 - 06:11

The only file in a clean installation of HEAD matching the pattern '\W+\Z' is misc/jquery.js, but it has a trailing end line. Can we consider this fixed?

#6

JamesAn - April 6, 2009 - 06:15
Status:active» needs review

While I'm at it, let's set the status to move this issue along.

Does someone want to confirm that all core files have a trailing newline?

#7

mcrittenden - April 21, 2009 - 00:04
Status:needs review» closed

misc/jquery.js is the only one that comes up for me, too.

#8

Dave Reid - April 21, 2009 - 00:08
Status:closed» active

That's no longer the pattern that needs to be checked. We want to ensure that all files in core end in exactly one new line, which matches several files.

#9

Dave Reid - April 21, 2009 - 00:21
Status:active» needs review
AttachmentSize
320114-coding-standards-ending-newlines-D7.patch 32.76 KB
Testbed results
320114-coding-standards-ending-newlines-D7.patchfailedFailed: Invalid PHP syntax in modules/contact/contact.pages.inc. Detailed results

#10

Dave Reid - April 21, 2009 - 00:27

Oops...left a spare part of a contact.module patch in there.

AttachmentSize
320114-coding-standards-ending-newlines-D7.patch 30.28 KB
Testbed results
320114-coding-standards-ending-newlines-D7.patchfailedFailed: Failed to apply patch. Detailed results

#11

mcrittenden - April 21, 2009 - 00:54

Went through the first 15 or so changes and everything checked out. Patch applies cleanly and works fine. Follows standards. Don't really know how to review it except to say that :).

#12

System Message - April 26, 2009 - 02:40
Status:needs review» needs work

The last submitted patch failed testing.

#13

JamesAn - April 28, 2009 - 19:14
Status:needs work» needs review

Let's retest.

#14

System Message - April 28, 2009 - 19:26
Status:needs review» needs work

The last submitted patch failed testing.

#15

JamesAn - May 29, 2009 - 20:59

Bump..

The patch no longer works due to all the intervening changes to the code. Is there some automated process to pick out all files in core that don't end in one new line and make them end in exactly one new line?

I'd reroll this if I knew how, but I suspect I'm going to waste a lot of time playing around with line endings...

#16

alexanderpas - June 12, 2009 - 20:13
Priority:minor» critical
Status:needs work» needs review

rerolled, temporarily critical, due to amount of changes.

this patch was made possible thanks to the song Code Monkey by Jonathan Coulton
http://www.jonathancoulton.com/2006/04/14/thing-a-week-29-code-monkey/

AttachmentSize
EOF-fixing.patch 31 KB
Testbed results
EOF-fixing.patchfailedFailed: Failed to apply patch. Detailed results

#17

alexanderpas - June 12, 2009 - 20:17
Assigned to:Anonymous» alexanderpas

#18

System Message - June 12, 2009 - 20:20
Status:needs review» needs work

The last submitted patch failed testing.

#19

alexanderpas - June 12, 2009 - 20:35
Status:needs work» needs review

what happened bot?
- Failed to install HEAD
- WTF??? stupid bot!!!

#20

System Message - June 12, 2009 - 21:11
Status:needs review» needs work

The last submitted patch failed testing.

#21

alexanderpas - June 12, 2009 - 22:20
Status:needs work» needs review

do not trust the bot: http://testing.drupal.org/node/33

#22

System Message - June 13, 2009 - 12:51
Status:needs review» needs work

The last submitted patch failed testing.

#23

lilou - June 13, 2009 - 14:01
Status:needs work» needs review

Setting to previous status - testbot was broken (failed to install).

#24

alexanderpas - June 13, 2009 - 16:54

and it passes, testbot is not broken anymore :D

note that there are no new-line warnings in the adds, and all newline removals were duplicate newlines at the end of the file.

#25

JamesAn - June 13, 2009 - 19:58

Thanks for that.

How'd you find the files with newline problem? Was it just figuring out the right regex string?

#26

alexanderpas - June 13, 2009 - 22:34

did not even used regex ;)

0) remove CVS and binary (images) files!!!
1) append unique identifier to all and every file
2) search and replace magic
3) create intermediate.patch
4) check out CVS again
5) apply intermediate patch to clean CVS checkout
6) no problems :D
7) cvs diff
8) patch ready!

#27

JamesAn - June 14, 2009 - 03:16

Oh. I see..

I was hoping for a quick way of doing it. =P Turns out, grep can't search across multiple lines anyway...

#28

System Message - June 19, 2009 - 09:30
Status:needs review» needs work

The last submitted patch failed testing.

#29

webchick - June 19, 2009 - 17:53
Priority:critical» minor

This isn't critical.

I'm also heavily considering "won't fix"ing this. I don't think we'll ever reach a point where everyone's editors aren't (re-)introducing/stripping these trailing whitespaces, so this kind of feels like a fight we're never going to win.

#30

Dave Reid - June 19, 2009 - 18:09

If we can get the core committers to run patches through some kind of automatic coder review, it won't matter anymore. That would be sweet. :) My original point is that newbies creating patches that don't have an ending new line are going to see those wacky lines in their patches and will freak out thinking they did it wrong.

#31

sun - June 19, 2009 - 19:44

At least, we should add this to the coding standards.

/me hates missing newline at end of file

#32

webchick - June 19, 2009 - 20:07

sun: That sounds reasonable. Want to take care of it?

Dave: I know, but there are obviously editors out there that are stripping out trailing newlines, or this wouldn't come up all the time. And rather than core committers doing this, the testing bot should do this. Then it could be fixed way before it ever hits RTBC. I know there must be an issue for this somewhere but I can't find it.

#33

sun - June 19, 2009 - 20:16
Project:Drupal» Coder
Version:7.x-dev» 7.x-1.x-dev
Component:other» Review/Rules

Moving to Coder's queue.

#34

Dave Reid - June 19, 2009 - 20:18

@webchick: Oh yeah having it automated by the bot is a way better idea. I love it!

#35

alexanderpas - September 2, 2009 - 21:22
Assigned to:alexanderpas» Anonymous
 
 

Drupal is a registered trademark of Dries Buytaert.