lint from root

This commit is contained in:
chico 2015-02-20 04:06:15 +03:00
parent c889f409bf
commit 466f4faf4e
13 changed files with 88 additions and 26 deletions

View File

@ -7,5 +7,10 @@ src/**/__tests__/**
# This should be enabled but that folder has too much in it that doesn't belong
src/test
test/the-files-to-test.generated.js
# This is synced with a different file internally, don't want to lint it yet
vendor/fbtransform/syntax.js
vendor/
# But not in docs/_js/examples/*
docs/_js/*.js
docs/js/
# This should be more like examples/**/thirdparty/** but
# we should fix https://github.com/facebook/esprima/pull/85 first
examples/

View File

@ -0,0 +1,3 @@
rules:
block-scoped-var: false
no-undef: false

View File

@ -1,3 +1,5 @@
'use strict';
var argv = require('optimist').argv;
var fs = require('fs');
@ -5,9 +7,9 @@ var CODE_SAMPLE = /```[\S]+\s*[\s\S]*?```/g;
var PARTS = /```[\S]+\s*\/\/\s+(.+?)\n([\s\S]*?)```/;
function truncate(s, n) {
n = n || 256
n = n || 256;
if (s.length < n) {
return s;
return s;
}
return s.substring(0, n) + '...';
}
@ -27,9 +29,9 @@ function main(dest, filenames) {
if (!extracted) {
throw new Error('Code sample did not match correct format in ' + filename + ': ' + truncate(codeSample));
}
var filename = extracted[1];
var content = extracted[2].replace(/\*\*/g, '');
fs.writeFileSync(argv.dest + '/' + filename, content);
var codeSampleFilename = extracted[1];
var codeSampleContent = extracted[2].replace(/\*\*/g, '');
fs.writeFileSync(argv.dest + '/' + codeSampleFilename, codeSampleContent);
});
});
}

View File

@ -0,0 +1,42 @@
'use strict';
function computeBallmerPeak(x) {
// see: http://ask.metafilter.com/76859/Make-a-function-of-this-graph-Thats-like-an-antigraph
x = x * 100;
return (
1 - 1 / (1 + Math.exp(-(x - 6))) *.5 + Math.exp(-Math.pow(Math.abs(x - 10), 2) * 10)
) / 1.6;
}
function percentage(x) {
return isNaN(x) ? 'N/A' : (100 - Math.round(x * 100)) + '%';
}
var BallmerPeakCalculator = React.createClass({
getInitialState: function() {
return {bac: 0};
},
handleChange: function(event) {
this.setState({bac: event.target.value});
},
render: function() {
var pct = percentage(computeBallmerPeak(this.state.bac));
return (
<div>
<img src="./ballmer_peak.png" />
<p>Credit due to <a href="http://xkcd.com/323/">xkcd</a>.</p>
<h4>Compute your Ballmer Peak:</h4>
<p>
If your BAC is{' '}
<input type="text" onChange={this.handleChange} value={this.state.bac} />
{', '}then <b>{pct}</b> of your lines of code will be bug free.
</p>
</div>
);
}
});
React.render(
<BallmerPeakCalculator />,
document.getElementById('container')
);

View File

@ -1,3 +1,5 @@
'use strict';
var React = require('react');
var ExampleApplication = React.createClass({

View File

@ -1,3 +1,5 @@
'use strict';
// Simple pure-React component so we don't have to remember
// Bootstrap's classes
var BootstrapButton = React.createClass({

View File

@ -1,3 +1,5 @@
'use strict';
var React = require('react');
var App = React.createClass({

View File

@ -1,3 +1,5 @@
'use strict';
var React = require('react');
var express = require('express');
var path = require('path');
@ -11,9 +13,9 @@ var app = express();
// in the querystring and return a static HTML representation of the component.
// Note that this is a backend service hit by your actual web app. Even so,
// you would probably put Varnish in front of this in production.
app.get('/', function(req, res){
var component = require(path.resolve(req.query['module']));
var props = JSON.parse(req.query['props'] || '{}');
app.get('/', function(req, res) {
var component = require(path.resolve(req.query.module));
var props = JSON.parse(req.query.props || '{}');
res.send(React.renderToString(component(props)));
});

View File

@ -6,15 +6,7 @@ module.exports = function() {
var done = this.async();
grunt.util.spawn({
cmd: 'node_modules/.bin/eslint',
args: [
'src/',
'Gruntfile.js',
'grunt/',
'main.js',
'perf/',
'test/',
'vendor/fbtransform'
]
args: ['.']
}, function(err, result, code) {
if (err) {
grunt.log.error('Lint failed');

View File

@ -1,4 +1,4 @@
"use strict";
'use strict';
var ReactTools = require('../main.js');

View File

@ -31,9 +31,15 @@ function compile(defaultLib, content, contentFilename) {
throw new Error('Expected only one dependency.');
}
},
getCanonicalFileName: function(filename) { return filename; },
getCurrentDirectory: function() { return ''; },
getNewLine: function() { return '\n'; }
getCanonicalFileName: function(filename) {
return filename;
},
getCurrentDirectory: function() {
return '';
},
getNewLine: function() {
return '\n';
}
};
var program = ts.createProgram([contentFilename], tsOptions, compilerHost);
var errors = program.getDiagnostics();

View File

@ -1,12 +1,14 @@
#!/usr/bin/env node
'use strict';
var esprima = require('esprima-fb');
var FileFinder = require('node-find-files');
var fs = require('graceful-fs');
var jstransform = require('jstransform');
var path = require('path');
var visitReactTag = require('./transforms/react').visitReactTag;
/*eslint-disable no-shadow*/
var S = esprima.Syntax;
var USAGE =
@ -143,7 +145,9 @@ if (require.main === module) {
var absPath = path.resolve(arg);
fs.stat(absPath, function(err, stat) {
if (err) throw err;
if (err) {
throw err;
}
if (stat.isFile()) {
transformFile(absPath);

View File

@ -7,7 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
/*global exports:true*/
"use strict";
'use strict';
var Syntax = require('esprima-fb').Syntax;
var utils = require('jstransform/src/utils');