lint from root
chico committed
Feb 20, 2015 at 04:06 UTC
466f4faf4e61f93fb9c4b01b79c6cfbc250bb340
13 files changed
+88
-26
.eslintignore
+7
-2
@@ -7,5 +7,10 @@ src/**/__tests__/**
7
# This should be enabled but that folder has too much in it that doesn't belong
8
src/test
9
test/the-files-to-test.generated.js
10
-# This is synced with a different file internally, don't want to lint it yet
11
-vendor/fbtransform/syntax.js
10
+vendor/
11
+# But not in docs/_js/examples/*
12
+docs/_js/*.js
13
+docs/js/
14
+# This should be more like examples/**/thirdparty/** but
15
+# we should fix https://github.com/facebook/esprima/pull/85 first
16
+examples/
\ No newline at end of file
docs/_js/examples/.eslintrc
new
+3
@@ -0,0 +1,3 @@
1
+rules:
2
+ block-scoped-var: false
3
+ no-undef: false
\ No newline at end of file
docs/extractCode.js
+7
-5
@@ -1,3 +1,5 @@
1
+'use strict';
2
+
3
var argv = require('optimist').argv;
4
var fs = require('fs');
5
@@ -5,9 +7,9 @@ var CODE_SAMPLE = /```[\S]+\s*[\s\S]*?```/g;
7
var PARTS = /```[\S]+\s*\/\/\s+(.+?)\n([\s\S]*?)```/;
8
9
function truncate(s, n) {
8
- n = n || 256
10
+ n = n || 256;
11
if (s.length < n) {
10
- return s;
12
+ return s;
13
}
14
return s.substring(0, n) + '...';
15
}
@@ -27,9 +29,9 @@ function main(dest, filenames) {
29
if (!extracted) {
30
throw new Error('Code sample did not match correct format in ' + filename + ': ' + truncate(codeSample));
31
}
30
- var filename = extracted[1];
31
- var content = extracted[2].replace(/\*\*/g, '');
32
- fs.writeFileSync(argv.dest + '/' + filename, content);
32
+ var codeSampleFilename = extracted[1];
33
+ var codeSampleContent = extracted[2].replace(/\*\*/g, '');
34
+ fs.writeFileSync(argv.dest + '/' + codeSampleFilename, codeSampleContent);
35
});
36
});
37
}
examples/ballmer-peak/example.js
new
+42
@@ -0,0 +1,42 @@
1
+'use strict';
2
+
3
+function computeBallmerPeak(x) {
4
+ // see: http://ask.metafilter.com/76859/Make-a-function-of-this-graph-Thats-like-an-antigraph
5
+ x = x * 100;
6
+ return (
7
+ 1 - 1 / (1 + Math.exp(-(x - 6))) *.5 + Math.exp(-Math.pow(Math.abs(x - 10), 2) * 10)
8
+ ) / 1.6;
9
+}
10
+
11
+function percentage(x) {
12
+ return isNaN(x) ? 'N/A' : (100 - Math.round(x * 100)) + '%';
13
+}
14
+
15
+var BallmerPeakCalculator = React.createClass({
16
+ getInitialState: function() {
17
+ return {bac: 0};
18
+ },
19
+ handleChange: function(event) {
20
+ this.setState({bac: event.target.value});
21
+ },
22
+ render: function() {
23
+ var pct = percentage(computeBallmerPeak(this.state.bac));
24
+ return (
25
+ <div>
26
+ <img src="./ballmer_peak.png" />
27
+ <p>Credit due to <a href="http://xkcd.com/323/">xkcd</a>.</p>
28
+ <h4>Compute your Ballmer Peak:</h4>
29
+ <p>
30
+ If your BAC is{' '}
31
+ <input type="text" onChange={this.handleChange} value={this.state.bac} />
32
+ {', '}then <b>{pct}</b> of your lines of code will be bug free.
33
+ </p>
34
+ </div>
35
+ );
36
+ }
37
+});
38
+
39
+React.render(
40
+ <BallmerPeakCalculator />,
41
+ document.getElementById('container')
42
+);
examples/basic-commonjs/index.js
+2
@@ -1,3 +1,5 @@
1
+'use strict';
2
+
3
var React = require('react');
4
5
var ExampleApplication = React.createClass({
examples/jquery-bootstrap/js/app.js
+2
@@ -1,3 +1,5 @@
1
+'use strict';
2
+
3
// Simple pure-React component so we don't have to remember
4
// Bootstrap's classes
5
var BootstrapButton = React.createClass({
examples/server-rendering/jsapp/src/App.js
+2
@@ -1,3 +1,5 @@
1
+'use strict';
2
+
3
var React = require('react');
4
5
var App = React.createClass({
examples/server-rendering/reactserver/server.js
+5
-3
@@ -1,3 +1,5 @@
1
+'use strict';
2
+
3
var React = require('react');
4
var express = require('express');
5
var path = require('path');
@@ -11,9 +13,9 @@ var app = express();
13
// in the querystring and return a static HTML representation of the component.
14
// Note that this is a backend service hit by your actual web app. Even so,
15
// you would probably put Varnish in front of this in production.
14
-app.get('/', function(req, res){
15
- var component = require(path.resolve(req.query['module']));
16
- var props = JSON.parse(req.query['props'] || '{}');
16
+app.get('/', function(req, res) {
17
+ var component = require(path.resolve(req.query.module));
18
+ var props = JSON.parse(req.query.props || '{}');
19
20
res.send(React.renderToString(component(props)));
21
});
grunt/tasks/eslint.js
+1
-9
@@ -6,15 +6,7 @@ module.exports = function() {
6
var done = this.async();
7
grunt.util.spawn({
8
cmd: 'node_modules/.bin/eslint',
9
- args: [
10
- 'src/',
11
- 'Gruntfile.js',
12
- 'grunt/',
13
- 'main.js',
14
- 'perf/',
15
- 'test/',
16
- 'vendor/fbtransform'
17
- ]
9
+ args: ['.']
10
}, function(err, result, code) {
11
if (err) {
12
grunt.log.error('Lint failed');
jest/preprocessor.js
+1
-1
@@ -1,4 +1,4 @@
1
-"use strict";
1
+'use strict';
2
3
var ReactTools = require('../main.js');
4
jest/ts-preprocessor.js
+9
-3
@@ -31,9 +31,15 @@ function compile(defaultLib, content, contentFilename) {
31
throw new Error('Expected only one dependency.');
32
}
33
},
34
- getCanonicalFileName: function(filename) { return filename; },
35
- getCurrentDirectory: function() { return ''; },
36
- getNewLine: function() { return '\n'; }
34
+ getCanonicalFileName: function(filename) {
35
+ return filename;
36
+ },
37
+ getCurrentDirectory: function() {
38
+ return '';
39
+ },
40
+ getNewLine: function() {
41
+ return '\n';
42
+ }
43
};
44
var program = ts.createProgram([contentFilename], tsOptions, compilerHost);
45
var errors = program.getDiagnostics();
npm-jsx_orphaned_brackets_transformer/run.js
+6
-2
@@ -1,12 +1,14 @@
1
#!/usr/bin/env node
2
3
+'use strict';
4
+
5
var esprima = require('esprima-fb');
6
var FileFinder = require('node-find-files');
7
var fs = require('graceful-fs');
8
var jstransform = require('jstransform');
9
var path = require('path');
10
var visitReactTag = require('./transforms/react').visitReactTag;
9
-
11
+/*eslint-disable no-shadow*/
12
var S = esprima.Syntax;
13
14
var USAGE =
@@ -143,7 +145,9 @@ if (require.main === module) {
145
var absPath = path.resolve(arg);
146
147
fs.stat(absPath, function(err, stat) {
146
- if (err) throw err;
148
+ if (err) {
149
+ throw err;
150
+ }
151
152
if (stat.isFile()) {
153
transformFile(absPath);
npm-jsx_orphaned_brackets_transformer/transforms/react.js
+1
-1
@@ -7,7 +7,7 @@
7
* of patent rights can be found in the PATENTS file in the same directory.
8
*/
9
/*global exports:true*/
10
-"use strict";
10
+'use strict';
11
var Syntax = require('esprima-fb').Syntax;
12
var utils = require('jstransform/src/utils');
13