Opened 9 years ago

Closed 9 years ago

#3259 closed enhancement (wontfix)

[PATCH] Clean javascript code syntax of for loops

Reported by: elexis Owned by:
Priority: If Time Permits Milestone:
Component: UI & Simulation Keywords: patch
Cc: Patch:

Description

The attached patch fixes the code style of all for loops and changes all occurances of i++ to ++i (for all variable names). I created the patch the following way:

  1. Identify loops with undesired style:
    cd "trunk/binaries/data/mods/public";
    grep -R "++)" --include=*.js  *
    
  1. Extract all variable names by hand and save to variables.txt
  1. Replace all increments with sed (execute in binaries/data/mods/public)
while read v; do
	find . -name "*.js" -print | xargs sed -i "s/ ${v}++/ ++${v}/g"
done <variables.txt
  1. Create a minimalist patch without unified context:
svn diff --diff-cmd diff -x "-U0" http://svn.wildfiregames.com/public/ps/trunk/ > patch

leper suggested some sed magic to combine steps 1-3 (not tested):

s/(for[ ]*\([^;];[^;];)([ ]*[^)+])+\+/$1\+\+$2/g

The patch should be ready to commit anyway.

Another thing that might be corrected automatically are those brackets { after for keywords, where a newline should be inserted and not only a space.

Attachments (1)

t3259_clean_for_loops_v1.patch.7z (8.4 KB ) - added by elexis 9 years ago.

Download all attachments as: .zip

Change History (3)

by elexis, 9 years ago

comment:1 by Itms, 9 years ago

I think someone else said it on IRC but this kind of patch is not really good, it's nicer to include style enhancements in other patches.

comment:2 by leper, 9 years ago

Keywords: review removed
Milestone: Backlog
Resolution: wontfix
Status: newclosed

Especially since some of those loops could be changed to other ones if it makes more sense so I'd rather do it when we touch code in that files already instead of doing one big commit that might not fix things in the best way possible.

Note: See TracTickets for help on using tickets.