mirror of
https://github.com/zebrajr/react.git
synced 2025-12-06 00:20:04 +01:00
lint from root
This commit is contained in:
parent
c889f409bf
commit
466f4faf4e
|
|
@ -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/
|
||||
3
docs/_js/examples/.eslintrc
Normal file
3
docs/_js/examples/.eslintrc
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
rules:
|
||||
block-scoped-var: false
|
||||
no-undef: false
|
||||
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
42
examples/ballmer-peak/example.js
Normal file
42
examples/ballmer-peak/example.js
Normal 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')
|
||||
);
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
var React = require('react');
|
||||
|
||||
var ExampleApplication = React.createClass({
|
||||
|
|
|
|||
2
examples/jquery-bootstrap/js/app.js
vendored
2
examples/jquery-bootstrap/js/app.js
vendored
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
// Simple pure-React component so we don't have to remember
|
||||
// Bootstrap's classes
|
||||
var BootstrapButton = React.createClass({
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
var React = require('react');
|
||||
|
||||
var App = React.createClass({
|
||||
|
|
|
|||
|
|
@ -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)));
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
"use strict";
|
||||
'use strict';
|
||||
|
||||
var ReactTools = require('../main.js');
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user