mirror of
https://github.com/facebook/react.git
synced 2026-02-26 18:58:05 +00:00
Merge pull request #3147 from hzoo/lint-fixes
lint whitespace , trailing comma
This commit is contained in:
@@ -5,33 +5,33 @@ var CODE_SAMPLE = /```[\S]+\s*[\s\S]*?```/g;
|
||||
var PARTS = /```[\S]+\s*\/\/\s+(.+?)\n([\s\S]*?)```/;
|
||||
|
||||
function truncate(s, n) {
|
||||
n = n || 256
|
||||
if (s.length < n) {
|
||||
return s;
|
||||
}
|
||||
return s.substring(0, n) + '...';
|
||||
n = n || 256
|
||||
if (s.length < n) {
|
||||
return s;
|
||||
}
|
||||
return s.substring(0, n) + '...';
|
||||
}
|
||||
|
||||
function main(dest, filenames) {
|
||||
if (!dest) {
|
||||
throw new Error('no dest provided');
|
||||
}
|
||||
filenames.map(function (filename) {
|
||||
var content = fs.readFileSync(filename).toString('utf8');
|
||||
var codeSamples = content.match(CODE_SAMPLE);
|
||||
if (!dest) {
|
||||
throw new Error('no dest provided');
|
||||
}
|
||||
filenames.map(function(filename) {
|
||||
var content = fs.readFileSync(filename).toString('utf8');
|
||||
var codeSamples = content.match(CODE_SAMPLE);
|
||||
|
||||
codeSamples.map(function (codeSample) {
|
||||
// Do a little jank preprocessing
|
||||
codeSample = codeSample.replace('<!--', '//').replace(' -->', '');
|
||||
var extracted = codeSample.match(PARTS);
|
||||
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);
|
||||
});
|
||||
codeSamples.map(function(codeSample) {
|
||||
// Do a little jank preprocessing
|
||||
codeSample = codeSample.replace('<!--', '//').replace(' -->', '');
|
||||
var extracted = codeSample.match(PARTS);
|
||||
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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
main(argv.dest, argv._);
|
||||
main(argv.dest, argv._);
|
||||
|
||||
@@ -42,7 +42,7 @@ describe('update', function() {
|
||||
expect(update([1, 4, 3], {$splice: [[1, 1, 2]]})).toEqual([1, 2, 3]);
|
||||
expect(update.bind(null, [], {$splice: 1})).toThrow(
|
||||
'Invariant Violation: update(): expected spec of $splice to be an ' +
|
||||
'array of arrays; got 1. Did you forget to wrap your parameters in an '+
|
||||
'array of arrays; got 1. Did you forget to wrap your parameters in an ' +
|
||||
'array?'
|
||||
);
|
||||
expect(update.bind(null, [], {$splice: [1]})).toThrow(
|
||||
|
||||
@@ -41,7 +41,7 @@ describe('findDOMNode', function() {
|
||||
});
|
||||
|
||||
it('findDOMNode should reject unmounted objects with render func', function() {
|
||||
expect(function() {React.findDOMNode({render: function(){}});})
|
||||
expect(function() {React.findDOMNode({render: function() {}});})
|
||||
.toThrow('Invariant Violation: Component (with keys: render) ' +
|
||||
'contains `render` method but is not mounted in the DOM'
|
||||
);
|
||||
|
||||
@@ -213,7 +213,7 @@ describe('ReactDOMComponent', function() {
|
||||
var genMarkup;
|
||||
|
||||
function quoteRegexp(str) {
|
||||
return (str+'').replace(/([.?*+\^$\[\]\\(){}|-])/g, "\\$1");
|
||||
return (str + '').replace(/([.?*+\^$\[\]\\(){}|-])/g, "\\$1");
|
||||
}
|
||||
|
||||
beforeEach(function() {
|
||||
@@ -266,7 +266,7 @@ describe('ReactDOMComponent', function() {
|
||||
var genMarkup;
|
||||
|
||||
function quoteRegexp(str) {
|
||||
return (str+'').replace(/([.?*+\^$\[\]\\(){}|-])/g, "\\$1");
|
||||
return (str + '').replace(/([.?*+\^$\[\]\\(){}|-])/g, "\\$1");
|
||||
}
|
||||
|
||||
beforeEach(function() {
|
||||
@@ -491,7 +491,7 @@ describe('ReactDOMComponent', function() {
|
||||
var ReactTestUtils = require('ReactTestUtils');
|
||||
|
||||
spyOn(console, 'warn');
|
||||
ReactTestUtils.renderIntoDocument(<div onScroll={function(){}} />);
|
||||
ReactTestUtils.renderIntoDocument(<div onScroll={function() {}} />);
|
||||
expect(console.warn.calls.length).toBe(1);
|
||||
expect(console.warn.mostRecentCall.args[0]).toBe(
|
||||
'Warning: This browser doesn\'t support the `onScroll` event'
|
||||
|
||||
@@ -322,7 +322,7 @@ describe('ReactElementValidator', function() {
|
||||
expect(console.warn.calls.length).toBe(2);
|
||||
});
|
||||
|
||||
it('should warn if a fragment is used without the wrapper', function () {
|
||||
it('should warn if a fragment is used without the wrapper', function() {
|
||||
spyOn(console, 'warn');
|
||||
var child = React.createElement('span');
|
||||
React.createElement('div', null, { a: child, b: child });
|
||||
|
||||
@@ -478,7 +478,7 @@ describe('ReactCompositeComponent', function() {
|
||||
|
||||
it('should warn when shouldComponentUpdate() returns undefined', function() {
|
||||
var Component = React.createClass({
|
||||
getInitialState: function () {
|
||||
getInitialState: function() {
|
||||
return {bogus: false};
|
||||
},
|
||||
|
||||
@@ -623,8 +623,8 @@ describe('ReactCompositeComponent', function() {
|
||||
|
||||
expect(console.warn.argsForCall.length).toBe(1);
|
||||
expect(console.warn.argsForCall[0][0]).toBe(
|
||||
'Warning: owner-based and parent-based contexts differ '+
|
||||
'(values: `bar` vs `undefined`) for key (foo) '+
|
||||
'Warning: owner-based and parent-based contexts differ ' +
|
||||
'(values: `bar` vs `undefined`) for key (foo) ' +
|
||||
'while mounting Component (see: http://fb.me/react-context-by-parent)'
|
||||
);
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ describe('ReactCompositeComponentNestedState-state', function() {
|
||||
|
||||
handleColor: function(color) {
|
||||
this.props.logger('parent-handleColor', this.state.color);
|
||||
this.setState({ color: color }, function () {
|
||||
this.setState({ color: color }, function() {
|
||||
this.props.logger('parent-after-setState', this.state.color);
|
||||
});
|
||||
},
|
||||
@@ -55,11 +55,11 @@ describe('ReactCompositeComponentNestedState-state', function() {
|
||||
handleHue: function(shade, color) {
|
||||
this.props.logger('handleHue', this.state.hue, this.props.color);
|
||||
this.props.onSelectColor(color);
|
||||
this.setState(function (state, props) {
|
||||
this.setState(function(state, props) {
|
||||
this.props.logger('setState-this', this.state.hue, this.props.color);
|
||||
this.props.logger('setState-args', state.hue, props.color);
|
||||
return { hue: shade + ' ' + props.color }
|
||||
}, function () {
|
||||
}, function() {
|
||||
this.props.logger('after-setState', this.state.hue, this.props.color);
|
||||
});
|
||||
},
|
||||
@@ -109,7 +109,7 @@ describe('ReactCompositeComponentNestedState-state', function() {
|
||||
[ 'setState-args', 'dark blue', 'green' ],
|
||||
[ 'render', 'light green', 'green' ],
|
||||
[ 'parent-after-setState', 'green' ],
|
||||
[ 'after-setState', 'light green', 'green' ],
|
||||
[ 'after-setState', 'light green', 'green' ]
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -57,14 +57,14 @@ describe('ReactCompositeComponent-state', function() {
|
||||
|
||||
componentWillMount: function() {
|
||||
this.peekAtState('componentWillMount-start');
|
||||
this.setState(function (state) {
|
||||
this.setState(function(state) {
|
||||
this.peekAtState('before-setState-sunrise', state);
|
||||
});
|
||||
this.setState(
|
||||
{color: 'sunrise'},
|
||||
this.peekAtCallback('setState-sunrise')
|
||||
);
|
||||
this.setState(function (state) {
|
||||
this.setState(function(state) {
|
||||
this.peekAtState('after-setState-sunrise', state);
|
||||
});
|
||||
this.peekAtState('componentWillMount-after-sunrise');
|
||||
@@ -72,7 +72,7 @@ describe('ReactCompositeComponent-state', function() {
|
||||
{color: 'orange'},
|
||||
this.peekAtCallback('setState-orange')
|
||||
);
|
||||
this.setState(function (state) {
|
||||
this.setState(function(state) {
|
||||
this.peekAtState('after-setState-orange', state);
|
||||
});
|
||||
this.peekAtState('componentWillMount-end');
|
||||
@@ -90,19 +90,19 @@ describe('ReactCompositeComponent-state', function() {
|
||||
componentWillReceiveProps: function(newProps) {
|
||||
this.peekAtState('componentWillReceiveProps-start');
|
||||
if (newProps.nextColor) {
|
||||
this.setState(function (state) {
|
||||
this.setState(function(state) {
|
||||
this.peekAtState('before-setState-receiveProps', state);
|
||||
return {color: newProps.nextColor};
|
||||
});
|
||||
this.replaceState({ color: undefined });
|
||||
this.setState(
|
||||
function (state) {
|
||||
function(state) {
|
||||
this.peekAtState('before-setState-again-receiveProps', state);
|
||||
return {color: newProps.nextColor};
|
||||
},
|
||||
this.peekAtCallback('setState-receiveProps')
|
||||
);
|
||||
this.setState(function (state) {
|
||||
this.setState(function(state) {
|
||||
this.peekAtState('after-setState-receiveProps', state);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ function verifyDomOrderingAccurate(parentInstance, statusDisplays) {
|
||||
var statusDisplayNodes = containerNode.childNodes;
|
||||
var i;
|
||||
var orderedDomIds = [];
|
||||
for (i=0; i < statusDisplayNodes.length; i++) {
|
||||
for (i = 0; i < statusDisplayNodes.length; i++) {
|
||||
orderedDomIds.push(ReactMount.getID(statusDisplayNodes[i]));
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
var React = require('React');
|
||||
var ReactTestUtils = require('ReactTestUtils');
|
||||
var reactComponentExpect= require('reactComponentExpect');
|
||||
var reactComponentExpect = require('reactComponentExpect');
|
||||
|
||||
var TestComponent = React.createClass({
|
||||
render: function() {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
var React = require('React');
|
||||
var ReactTestUtils = require('ReactTestUtils');
|
||||
|
||||
var reactComponentExpect= require('reactComponentExpect');
|
||||
var reactComponentExpect = require('reactComponentExpect');
|
||||
|
||||
|
||||
/**
|
||||
@@ -34,7 +34,7 @@ var ClickCounter = React.createClass({
|
||||
render: function() {
|
||||
var children = [];
|
||||
var i;
|
||||
for (i=0; i < this.state.count; i++) {
|
||||
for (i = 0; i < this.state.count; i++) {
|
||||
children.push(
|
||||
<div
|
||||
className="clickLogDiv"
|
||||
|
||||
@@ -170,7 +170,7 @@ var ReactTestUtils = {
|
||||
var all =
|
||||
ReactTestUtils.scryRenderedDOMComponentsWithClass(root, className);
|
||||
if (all.length !== 1) {
|
||||
throw new Error('Did not find exactly one match '+
|
||||
throw new Error('Did not find exactly one match ' +
|
||||
'(found: ' + all.length + ') for class:' + className
|
||||
);
|
||||
}
|
||||
|
||||
@@ -116,8 +116,8 @@ function makeComponent(metadata) {
|
||||
f._isMockFunction = true;
|
||||
|
||||
f.mock = {
|
||||
calls : calls,
|
||||
instances : instances
|
||||
calls: calls,
|
||||
instances: instances
|
||||
};
|
||||
|
||||
f.mockClear = function() {
|
||||
@@ -218,7 +218,7 @@ function _getMetadata(component, _refs) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var metadata = {type : type};
|
||||
var metadata = {type: type};
|
||||
if (type == 'constant') {
|
||||
metadata.value = component;
|
||||
return metadata;
|
||||
|
||||
@@ -3,14 +3,14 @@
|
||||
|
||||
if (typeof console == 'undefined') {
|
||||
this.console = {
|
||||
error: function(e){
|
||||
error: function(e) {
|
||||
postMessage(JSON.stringify({
|
||||
type: 'error',
|
||||
message: e.message,
|
||||
stack: e.stack
|
||||
}));
|
||||
},
|
||||
log: function(message){
|
||||
log: function(message) {
|
||||
postMessage(JSON.stringify({
|
||||
type: 'log',
|
||||
message: message
|
||||
|
||||
@@ -78,7 +78,7 @@ var hasUndefinedStringKey = [
|
||||
var hasPositiveNumericKey = [
|
||||
{uniqueID: 'notANumber', data: []},
|
||||
{uniqueID: '5', data: []},
|
||||
{uniqueID: 'notAnotherNumber',data: []}
|
||||
{uniqueID: 'notAnotherNumber', data: []}
|
||||
];
|
||||
|
||||
var hasZeroStringKey = [
|
||||
|
||||
@@ -421,7 +421,7 @@ describe('ReactChildren', function() {
|
||||
expect(numberOfChildren).toBe(6);
|
||||
});
|
||||
|
||||
it('should warn if a fragment is used without the wrapper', function () {
|
||||
it('should warn if a fragment is used without the wrapper', function() {
|
||||
spyOn(console, 'warn');
|
||||
var child = React.createElement('span');
|
||||
ReactChildren.forEach({ a: child, b: child}, function(c) {
|
||||
@@ -431,7 +431,7 @@ describe('ReactChildren', function() {
|
||||
expect(console.warn.calls[0].args[0]).toContain('use of a keyed object');
|
||||
});
|
||||
|
||||
it('should warn if a fragment is accessed', function () {
|
||||
it('should warn if a fragment is accessed', function() {
|
||||
spyOn(console, 'warn');
|
||||
var child = React.createElement('span');
|
||||
var frag = ReactChildren.map([ child, child ], function(c) {
|
||||
|
||||
@@ -351,7 +351,7 @@ describe('traverseAllChildren', function() {
|
||||
return {
|
||||
next: function() {
|
||||
if (i++ < 3) {
|
||||
return { value: <div key={'#'+i} />, done: false };
|
||||
return { value: <div key={'#' + i} />, done: false };
|
||||
} else {
|
||||
return { value: undefined, done: true };
|
||||
}
|
||||
@@ -402,7 +402,7 @@ describe('traverseAllChildren', function() {
|
||||
return {
|
||||
next: function() {
|
||||
if (i++ < 3) {
|
||||
return { value: ['#'+i, <div />], done: false };
|
||||
return { value: ['#' + i, <div />], done: false };
|
||||
} else {
|
||||
return { value: undefined, done: true };
|
||||
}
|
||||
|
||||
4
vendor/fbtransform/syntax.js
vendored
4
vendor/fbtransform/syntax.js
vendored
@@ -57,10 +57,10 @@ function runCli(argv) {
|
||||
var source = '';
|
||||
process.stdin.resume();
|
||||
process.stdin.setEncoding('utf8');
|
||||
process.stdin.on('data', function (chunk) {
|
||||
process.stdin.on('data', function(chunk) {
|
||||
source += chunk;
|
||||
});
|
||||
process.stdin.on('end', function () {
|
||||
process.stdin.on('end', function() {
|
||||
try {
|
||||
source = transformAll(source, options, excludes);
|
||||
} catch (e) {
|
||||
|
||||
@@ -338,7 +338,7 @@ describe('react jsx', function() {
|
||||
|
||||
it('should not throw for unknown hyphenated tags', function() {
|
||||
var code = '<x-component />;';
|
||||
expect(function(){transform(code);}).not.toThrow();
|
||||
expect(function() {transform(code);}).not.toThrow();
|
||||
});
|
||||
|
||||
it('calls assign with a new target object for spreads', function() {
|
||||
|
||||
4
vendor/fbtransform/transforms/xjs.js
vendored
4
vendor/fbtransform/transforms/xjs.js
vendored
@@ -20,13 +20,13 @@ function renderXJSLiteral(object, isLast, state, start, end) {
|
||||
|
||||
var lastNonEmptyLine = 0;
|
||||
|
||||
lines.forEach(function (line, index) {
|
||||
lines.forEach(function(line, index) {
|
||||
if (line.match(/[^ \t]/)) {
|
||||
lastNonEmptyLine = index;
|
||||
}
|
||||
});
|
||||
|
||||
lines.forEach(function (line, index) {
|
||||
lines.forEach(function(line, index) {
|
||||
var isFirstLine = index === 0;
|
||||
var isLastLine = index === lines.length - 1;
|
||||
var isLastNonEmptyLine = index === lastNonEmptyLine;
|
||||
|
||||
Reference in New Issue
Block a user