Merge lp:~makyo/juju-gui/recess into lp:juju-gui/experimental

Proposed by Madison Scott-Clary
Status: Merged
Merged at revision: 312
Proposed branch: lp:~makyo/juju-gui/recess
Merge into: lp:juju-gui/experimental
Diff against target: 112 lines (+43/-17)
4 files modified
Makefile (+5/-2)
lib/templates.js (+30/-15)
package.json (+1/-0)
recess.json (+7/-0)
To merge this branch: bzr merge lp:~makyo/juju-gui/recess
Reviewer Review Type Date Requested Status
Juju GUI Hackers Pending
Review via email: mp+142572@code.launchpad.net

Description of the change

Use recess as CSS linter

This is the first step to implementing a CSS linter (recess). Currently, most of the options are turned off in order to keep this slack task short, so our LESS file passes the linter. Further slack tasks may be created for options that we decide to turn on down the road (personal suggestions: noOverqualifying and zeroUnits, ambivalent about strictPropertyOrder).

https://codereview.appspot.com/7067057/

To post a comment you must log in.
Revision history for this message
Madison Scott-Clary (makyo) wrote :
Download full text (4.9 KiB)

Reviewers: mp+142572_code.launchpad.net,

Message:
Please take a look.

Description:
Use recess as CSS linter

This is the first step to implementing a CSS linter (recess).
Currently, most of the options are turned off in order to keep this
slack task short, so our LESS file passes the linter. Further slack
tasks may be created for options that we decide to turn on down the road
(personal suggestions: noOverqualifying and zeroUnits, ambivalent about
strictPropertyOrder). There is one work-around in place in
lib/templates.js due to https://github.com/twitter/recess/issues/22 in
that recess is called twice - once to lint and once to compile - in
order to side-step an OOM error. This is still quite fast, and not used
in production.

https://code.launchpad.net/~makyo/juju-gui/recess/+merge/142572

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/7067057/

Affected files:
   M Makefile
   A [revision details]
   M lib/templates.js
   M package.json
   A recess.json

Index: Makefile
=== modified file 'Makefile'
--- Makefile 2012-12-21 12:52:30 +0000
+++ Makefile 2013-01-09 18:36:08 +0000
@@ -38,7 +38,7 @@
   node_modules/minimatch node_modules/mocha node_modules/node-markdown \
   node_modules/node-minify node_modules/node-spritesheet \
   node_modules/rimraf node_modules/should node_modules/yui \
- node_modules/yuidocjs
+ node_modules/yuidocjs node_modules/recess
  EXPECTED_NODE_TARGETS=$(shell echo "$(NODE_TARGETS)" | tr ' ' '\n' | sort \
   | tr '\n' ' ')

@@ -223,7 +223,10 @@
  yuidoc-lint: $(JSFILES)
   bin/lint-yuidoc

-lint: gjslint jshint yuidoc-lint
+recess: node_modules/recess
+ recess lib/views/stylesheet.less --config recess.json | grep -q Perfect
+
+lint: gjslint jshint recess yuidoc-lint

  virtualenv/bin/gjslint virtualenv/bin/fixjsstyle:
   virtualenv virtualenv

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: <email address hidden>
+New revision: <email address hidden>

Index: package.json
=== modified file 'package.json'
--- package.json 2013-01-09 16:42:50 +0000
+++ package.json 2013-01-09 17:23:33 +0000
@@ -24,6 +24,7 @@
      "chai": ">=1.2.0",
      "less": "1.3.x",
      "jshint": ">=0.9.1",
+ "recess": "1.1.x",
      "node-markdown": "0.1.x",
      "yuidocjs": "0.3.x",
      "minimatch": "0.2.x",

Index: recess.json
=== added file 'recess.json'
--- recess.json 1970-01-01 00:00:00 +0000
+++ recess.json 2013-01-09 18:36:08 +0000
@@ -0,0 +1,7 @@
+{
+ "compile": false,
+ "noIDs": false,
+ "noOverqualifying": false,
+ "strictPropertyOrder": false,
+ "zeroUnits": false
+}

Index: lib/templates.js
=== modified file 'lib/templates.js'
--- lib/templates.js 2012-12-20 21:59:21 +0000
+++ lib/templates.js 2013-01-09 18:37:46 +0000
@@ -5,7 +5,7 @@
      exec = require('child_process').exec,
      YUI = require('yui').YUI,
      view = require('./view.js'),
- less = require('less'),
+ recess = require('recess'),
      config = require('../config.js').config,
  ...

Read more...

Revision history for this message
Gary Poster (gary) wrote :

land with changes.

Please apply the diff I gave, or do something similar. You don't need
to do anything about lib/templates.js. Let's stick with what you have.

Thank you!

Gary

https://codereview.appspot.com/7067057/diff/1/Makefile
File Makefile (right):

https://codereview.appspot.com/7067057/diff/1/Makefile#newcode227
Makefile:227: recess lib/views/stylesheet.less --config recess.json |
grep -q Perfect
This runs a global "recess" and not the one installed locally.
http://pastebin.ubuntu.com/1514675/ has a fix for this.

https://codereview.appspot.com/7067057/diff/1/Makefile#newcode465
Makefile:465: undocumented yuidoc yuidoc-lint
recess is a "PHONY" target because there is no "recess" file in the root
of the build. The pastebin also has this change.
http://pastebin.ubuntu.com/1514675/

https://codereview.appspot.com/7067057/diff/1/lib/templates.js
File lib/templates.js (right):

https://codereview.appspot.com/7067057/diff/1/lib/templates.js#newcode191
lib/templates.js:191: });
I wonder about this change, but I am OK with it. Simply using less and
relying on recess for later linting might be nicer. OTOH, maybe this
keeps us from falling over when the LESS file is bad.

https://codereview.appspot.com/7067057/

Revision history for this message
Nicola Larosa (teknico) wrote :

Land with (Gary's) changes.

No comments in addition to Gary's ones, this looks great, thanks.

https://codereview.appspot.com/7067057/

Revision history for this message
Madison Scott-Clary (makyo) wrote :

Thanks for the reviews.

https://codereview.appspot.com/7067057/diff/1/Makefile
File Makefile (right):

https://codereview.appspot.com/7067057/diff/1/Makefile#newcode227
Makefile:227: recess lib/views/stylesheet.less --config recess.json |
grep -q Perfect
On 2013/01/09 22:10:24, gary.poster wrote:
> This runs a global "recess" and not the one installed locally.
> http://pastebin.ubuntu.com/1514675/ has a fix for this.

Good catch! Had it installed globally for testing and had forgotten.
Applied the patch.

https://codereview.appspot.com/7067057/diff/1/lib/templates.js
File lib/templates.js (right):

https://codereview.appspot.com/7067057/diff/1/lib/templates.js#newcode191
lib/templates.js:191: });
On 2013/01/09 22:10:24, gary.poster wrote:
> I wonder about this change, but I am OK with it. Simply using less
and relying
> on recess for later linting might be nicer. OTOH, maybe this keeps us
from
> falling over when the LESS file is bad.

I reverted this change. recess just uses less to compile, and if the
LESS file is bad, the error we get is the error from the less package.
No real value added.

https://codereview.appspot.com/7067057/

Revision history for this message
Madison Scott-Clary (makyo) wrote :

*** Submitted:

Use recess as CSS linter

This is the first step to implementing a CSS linter (recess).
Currently, most of the options are turned off in order to keep this
slack task short, so our LESS file passes the linter. Further slack
tasks may be created for options that we decide to turn on down the road
(personal suggestions: noOverqualifying and zeroUnits, ambivalent about
strictPropertyOrder).

R=gary.poster, teknico
CC=
https://codereview.appspot.com/7067057

https://codereview.appspot.com/7067057/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'Makefile'
--- Makefile 2012-12-21 12:52:30 +0000
+++ Makefile 2013-01-09 18:46:30 +0000
@@ -38,7 +38,7 @@
38 node_modules/minimatch node_modules/mocha node_modules/node-markdown \38 node_modules/minimatch node_modules/mocha node_modules/node-markdown \
39 node_modules/node-minify node_modules/node-spritesheet \39 node_modules/node-minify node_modules/node-spritesheet \
40 node_modules/rimraf node_modules/should node_modules/yui \40 node_modules/rimraf node_modules/should node_modules/yui \
41 node_modules/yuidocjs41 node_modules/yuidocjs node_modules/recess
42EXPECTED_NODE_TARGETS=$(shell echo "$(NODE_TARGETS)" | tr ' ' '\n' | sort \42EXPECTED_NODE_TARGETS=$(shell echo "$(NODE_TARGETS)" | tr ' ' '\n' | sort \
43 | tr '\n' ' ')43 | tr '\n' ' ')
4444
@@ -223,7 +223,10 @@
223yuidoc-lint: $(JSFILES)223yuidoc-lint: $(JSFILES)
224 bin/lint-yuidoc224 bin/lint-yuidoc
225225
226lint: gjslint jshint yuidoc-lint226recess: node_modules/recess
227 recess lib/views/stylesheet.less --config recess.json | grep -q Perfect
228
229lint: gjslint jshint recess yuidoc-lint
227230
228virtualenv/bin/gjslint virtualenv/bin/fixjsstyle:231virtualenv/bin/gjslint virtualenv/bin/fixjsstyle:
229 virtualenv virtualenv232 virtualenv virtualenv
230233
=== modified file 'lib/templates.js'
--- lib/templates.js 2012-12-20 21:59:21 +0000
+++ lib/templates.js 2013-01-09 18:46:30 +0000
@@ -5,7 +5,7 @@
5 exec = require('child_process').exec,5 exec = require('child_process').exec,
6 YUI = require('yui').YUI,6 YUI = require('yui').YUI,
7 view = require('./view.js'),7 view = require('./view.js'),
8 less = require('less'),8 recess = require('recess'),
9 config = require('../config.js').config,9 config = require('../config.js').config,
10 cache = {};10 cache = {};
1111
@@ -159,21 +159,36 @@
159 stylesheet: {159 stylesheet: {
160 output: __dirname + '/../build-shared/juju-ui/assets/juju-gui.css',160 output: __dirname + '/../build-shared/juju-ui/assets/juju-gui.css',
161 callback: function(strategy, name) {161 callback: function(strategy, name) {
162 var parser = new less.Parser({162 // Lint the file without compiling using our config first.
163 paths: [config.server.view_dir],163 var recessConfig = JSON.parse(
164 filename: 'stylesheet.less'164 fs.readFileSync(__dirname + '/../recess.json'));
165 }),165 recess(
166 css_data = fs.readFileSync(166 path.join(config.server.view_dir, 'stylesheet.less'),
167 path.join(config.server.view_dir, 'stylesheet.less'), 'utf8');167 recessConfig,
168 parser.parse(css_data, function(e, tree) {168 function(err, obj) {
169 if (e) {169 if (err) {
170 console.log('LESS Generation Error', e);170 console.log('LESS Generation Error', err);
171 return;171 return;
172 }172 }
173 fs.writeFileSync(strategy.output,173 // Warn of lint errors.
174 tree.toCSS({compress: true}));174 console.log(obj.errors);
175 });175 });
176176
177 // Compile the less to the output file without worrying about our config.
178 // This is due to a memory-leak in recess when multiple options are
179 // specified with compile=true.
180 // See: https://github.com/twitter/recess/issues/22
181 recess(
182 path.join(config.server.view_dir, 'stylesheet.less'),
183 { compile: true },
184 function(err, obj) {
185 if (err) {
186 console.log('LESS Generation Error', err);
187 return;
188 }
189 // Write to output.
190 fs.writeFileSync(strategy.output, obj.output);
191 });
177 }192 }
178 }193 }
179};194};
180195
=== modified file 'package.json'
--- package.json 2013-01-09 16:42:50 +0000
+++ package.json 2013-01-09 18:46:30 +0000
@@ -24,6 +24,7 @@
24 "chai": ">=1.2.0",24 "chai": ">=1.2.0",
25 "less": "1.3.x",25 "less": "1.3.x",
26 "jshint": ">=0.9.1",26 "jshint": ">=0.9.1",
27 "recess": "1.1.x",
27 "node-markdown": "0.1.x",28 "node-markdown": "0.1.x",
28 "yuidocjs": "0.3.x",29 "yuidocjs": "0.3.x",
29 "minimatch": "0.2.x",30 "minimatch": "0.2.x",
3031
=== added file 'recess.json'
--- recess.json 1970-01-01 00:00:00 +0000
+++ recess.json 2013-01-09 18:46:30 +0000
@@ -0,0 +1,7 @@
1{
2 "compile": false,
3 "noIDs": false,
4 "noOverqualifying": false,
5 "strictPropertyOrder": false,
6 "zeroUnits": false
7}

Subscribers

People subscribed via source and target branches