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
1=== modified file 'Makefile'
2--- Makefile 2012-12-21 12:52:30 +0000
3+++ Makefile 2013-01-09 18:46:30 +0000
4@@ -38,7 +38,7 @@
5 node_modules/minimatch node_modules/mocha node_modules/node-markdown \
6 node_modules/node-minify node_modules/node-spritesheet \
7 node_modules/rimraf node_modules/should node_modules/yui \
8- node_modules/yuidocjs
9+ node_modules/yuidocjs node_modules/recess
10 EXPECTED_NODE_TARGETS=$(shell echo "$(NODE_TARGETS)" | tr ' ' '\n' | sort \
11 | tr '\n' ' ')
12
13@@ -223,7 +223,10 @@
14 yuidoc-lint: $(JSFILES)
15 bin/lint-yuidoc
16
17-lint: gjslint jshint yuidoc-lint
18+recess: node_modules/recess
19+ recess lib/views/stylesheet.less --config recess.json | grep -q Perfect
20+
21+lint: gjslint jshint recess yuidoc-lint
22
23 virtualenv/bin/gjslint virtualenv/bin/fixjsstyle:
24 virtualenv virtualenv
25
26=== modified file 'lib/templates.js'
27--- lib/templates.js 2012-12-20 21:59:21 +0000
28+++ lib/templates.js 2013-01-09 18:46:30 +0000
29@@ -5,7 +5,7 @@
30 exec = require('child_process').exec,
31 YUI = require('yui').YUI,
32 view = require('./view.js'),
33- less = require('less'),
34+ recess = require('recess'),
35 config = require('../config.js').config,
36 cache = {};
37
38@@ -159,21 +159,36 @@
39 stylesheet: {
40 output: __dirname + '/../build-shared/juju-ui/assets/juju-gui.css',
41 callback: function(strategy, name) {
42- var parser = new less.Parser({
43- paths: [config.server.view_dir],
44- filename: 'stylesheet.less'
45- }),
46- css_data = fs.readFileSync(
47- path.join(config.server.view_dir, 'stylesheet.less'), 'utf8');
48- parser.parse(css_data, function(e, tree) {
49- if (e) {
50- console.log('LESS Generation Error', e);
51- return;
52- }
53- fs.writeFileSync(strategy.output,
54- tree.toCSS({compress: true}));
55- });
56+ // Lint the file without compiling using our config first.
57+ var recessConfig = JSON.parse(
58+ fs.readFileSync(__dirname + '/../recess.json'));
59+ recess(
60+ path.join(config.server.view_dir, 'stylesheet.less'),
61+ recessConfig,
62+ function(err, obj) {
63+ if (err) {
64+ console.log('LESS Generation Error', err);
65+ return;
66+ }
67+ // Warn of lint errors.
68+ console.log(obj.errors);
69+ });
70
71+ // Compile the less to the output file without worrying about our config.
72+ // This is due to a memory-leak in recess when multiple options are
73+ // specified with compile=true.
74+ // See: https://github.com/twitter/recess/issues/22
75+ recess(
76+ path.join(config.server.view_dir, 'stylesheet.less'),
77+ { compile: true },
78+ function(err, obj) {
79+ if (err) {
80+ console.log('LESS Generation Error', err);
81+ return;
82+ }
83+ // Write to output.
84+ fs.writeFileSync(strategy.output, obj.output);
85+ });
86 }
87 }
88 };
89
90=== modified file 'package.json'
91--- package.json 2013-01-09 16:42:50 +0000
92+++ package.json 2013-01-09 18:46:30 +0000
93@@ -24,6 +24,7 @@
94 "chai": ">=1.2.0",
95 "less": "1.3.x",
96 "jshint": ">=0.9.1",
97+ "recess": "1.1.x",
98 "node-markdown": "0.1.x",
99 "yuidocjs": "0.3.x",
100 "minimatch": "0.2.x",
101
102=== added file 'recess.json'
103--- recess.json 1970-01-01 00:00:00 +0000
104+++ recess.json 2013-01-09 18:46:30 +0000
105@@ -0,0 +1,7 @@
106+{
107+ "compile": false,
108+ "noIDs": false,
109+ "noOverqualifying": false,
110+ "strictPropertyOrder": false,
111+ "zeroUnits": false
112+}

Subscribers

People subscribed via source and target branches