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
Code Style Improvements #4806
Code Style Improvements #4806
Conversation
git reset --hard codepainter xform -j ../utils/codestyle/mrdoob_codepainter.json "*/*.js" find ./ -type f -exec sed -i -e 's/( )/()/g;s/\[ \]/[]/g;s#{[ ]}#\{\}#g' {} \; find . -name "*.js-e*" -print0 | xargs -0 rm git add -p
This is sweet! Here are some things I noticed. Of course, it is @mrdoob's choice.
Replacing *.html example files could use this treatment, too. Why are the *.Loader files completely replaced? |
@zz85 any chance you can implement @WestLangley suggestions and run the script again? O:) |
sorry for the delay.. haven't had much free time the last week. yeah, I could probably regex search the replace the spaces for negation and increments. @mrdoob, what's your take on the use of quotes? |
JSCS rules: { "requireSpaceAfterPrefixUnaryOperators": [ "+", "-", "++", "--" ] }
JSCS rules: { "requireSpaceBeforePostfixUnaryOperators": ["++", "--"] }
Ok made changes @WestLangley pointed. Since auto-formatting is yet to be implemented (as @mikesherov has mentioned), I turned a custom error reporter in jscs into a code corrector for the unary operators. jscs rule {
"requireSpaceAfterPrefixUnaryOperators": [ "+", "-", "++", "--" ],
"requireSpaceBeforePostfixUnaryOperators": ["++", "--"]
} space.js var util = require('util');
var fs = require('fs');
/**
* @param {Errors[]} errorsCollection
*/
module.exports = function(errorsCollection) {
var errorCount = 0;
/**
* Fixes spacing errors.
*/
var json = {};
errorsCollection.forEach(function(errors) {
var file = errors.getFilename();
var file_contents = fs.readFileSync(file, 'utf-8');
var lines = file_contents.split('\n');
if (!errors.isEmpty()) {
var list = [];
errors.getErrorList().forEach(function(error) {
list.push({
line: error.line,
column: error.column,
message: error.message
})
errorCount++;
});
json[file] = list;
list = list.reverse();
list.forEach(function(error) {
var line = error.line - 1;
var str = lines[line];
var col = error.column;
while (str.charAt(col) != '+' && str.charAt(col) != '-') col++;
lines[line] = str.substring(0, col) + ' ' + str.substring(col);
console.log(str + ' --> ' + lines[line]);
});
file_contents = lines.join('\n');
// console.log('--preview formatted: ' + file + ' --')
// console.log(file_contents) // print formatted source
fs.writeFile(file, file_contents); // write formatted source
}
});
console.log('end', json, errorCount)
}; Command jscs src -c mrdoob.json -r spaces |
Thanks @zz85 ! I also see in
Should be spaces around
Perhaps there are others that need to be considered, like |
What happened to cause these files to be completely replaced in this PR? |
I'm not too sure ether... They look similar to me, I wonder if its some encoding stuff going on or something?
Good observation... I think
For now, I think it might be better for mrdoob to merge bulk of the code style changes if its ok and continue to improve more code style changes, just in case PRs by other users come in and makes it harder for merges. |
Seems like there are some conflicts again... :/ |
@mrdoob hmm... let me try on Sunday tomorrow. could we have a mini merge freeze so it wouldn't conflict again? @WestLangley right now its just a whole bunch of assorted scriptfu to get this done, but the process have been documented here. Until autoformatting comes in jscs, this process should be a one-off thing. (jscs has been making some progress lately, so hopefully things like this would be much easier in future). |
@WestLangley also, I'm have no idea why |
@WestLangley hmm.. I'm trying to do a git diff locally, but it doesn't show up any diffs. I can't tell if its a github issue or not... |
@WestLangley hmm... I think this is a CRLF issues. See http://lostechies.com/keithdahlby/2011/04/06/windows-git-tip-hide-carriage-return-in-diff/ I'll try with the git option crlf set to auto this time. |
not sure what @mrdoob's take on the CRLF issue... |
i'll try not changing line ending encodings for now.. |
@zz85 Many thanks for your excellent detective work! : - )
That is a good backup plan if the process can't be completely automated... Once you file your PR and get most of the formatting as desired, future format changes could be made manually whenever the script identifies ill-formatted lines. (In other words, formatting changes do not have to be completely automated.) |
Closing in favour of #4873 |
There's probably certain things which fell through the cracks, and several areas which I'm also not certain of @mrdoob's preferences. Nevertheless, first round attempt to code transform codebase mrdoob style using codepainter with some sed commands.
See #4802
cc. @WestLangley