Skip to content
16 changes: 8 additions & 8 deletions packages/react-dom/src/__tests__/ReactDOMComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,10 +443,10 @@ describe('ReactDOMComponent', () => {
});

it('should not set null/undefined attributes', () => {
var container = document.createElement('div');
const container = document.createElement('div');
// Initial render.
ReactDOM.render(<img src={null} data-foo={undefined} />, container);
var node = container.firstChild;
const node = container.firstChild;
expect(node.hasAttribute('src')).toBe(false);
expect(node.hasAttribute('data-foo')).toBe(false);
// Update in one direction.
Expand All @@ -468,9 +468,9 @@ describe('ReactDOMComponent', () => {
});

it('should apply React-specific aliases to HTML elements', () => {
var container = document.createElement('div');
const container = document.createElement('div');
ReactDOM.render(<form acceptCharset="foo" />, container);
var node = container.firstChild;
const node = container.firstChild;
// Test attribute initialization.
expect(node.getAttribute('accept-charset')).toBe('foo');
expect(node.hasAttribute('acceptCharset')).toBe(false);
Expand Down Expand Up @@ -501,9 +501,9 @@ describe('ReactDOMComponent', () => {
});

it('should apply React-specific aliases to SVG elements', () => {
var container = document.createElement('div');
const container = document.createElement('div');
ReactDOM.render(<svg arabicForm="foo" />, container);
var node = container.firstChild;
const node = container.firstChild;
// Test attribute initialization.
expect(node.getAttribute('arabic-form')).toBe('foo');
expect(node.hasAttribute('arabicForm')).toBe(false);
Expand Down Expand Up @@ -543,9 +543,9 @@ describe('ReactDOMComponent', () => {
});

it('should not apply React-specific aliases to custom elements', () => {
var container = document.createElement('div');
const container = document.createElement('div');
ReactDOM.render(<some-custom-element arabicForm="foo" />, container);
var node = container.firstChild;
const node = container.firstChild;
// Should not get transformed to arabic-form as SVG would be.
expect(node.getAttribute('arabicForm')).toBe('foo');
expect(node.hasAttribute('arabic-form')).toBe(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ describe('ReactDOMServer', () => {
it('should not focus on either server or client with autofocus={false} even if there is a markup mismatch', () => {
spyOnDev(console, 'error');

var element = document.createElement('div');
const element = document.createElement('div');
element.innerHTML = ReactDOMServer.renderToString(
<button autoFocus={false}>server</button>,
);
Expand Down
4 changes: 2 additions & 2 deletions packages/react-dom/src/__tests__/validateDOMNesting-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

'use strict';

var React = require('react');
var ReactDOM = require('react-dom');
const React = require('react');
const ReactDOM = require('react-dom');

function normalizeCodeLocInfo(str) {
return str && str.replace(/at .+?:\d+/g, 'at **');
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/src/events/forks/EventListener-www.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @flow
*/

var EventListenerWWW = require('EventListener');
const EventListenerWWW = require('EventListener');

import typeof * as EventListenerType from '../EventListener';
import typeof * as EventListenerShimType from './EventListener-www';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';

describe('transform-prevent-infinite-loops', () => {
// Note: instead of testing the transform by applying it,
Expand Down
4 changes: 2 additions & 2 deletions scripts/babel/transform-object-assign-require.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ module.exports = function autoImporter(babel) {
CallExpression: function(path, file) {
if (path.get('callee').matchesPattern('Object.assign')) {
// generate identifier and require if it hasn't been already
var id = getAssignIdent(path, file, this);
const id = getAssignIdent(path, file, this);
path.node.callee = id;
}
},

MemberExpression: function(path, file) {
if (path.matchesPattern('Object.assign')) {
var id = getAssignIdent(path, file, this);
const id = getAssignIdent(path, file, this);
path.replaceWith(id);
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('error codes transform', () => {
});

it('should only add `reactProdInvariant` once', () => {
var expectedInvariantTransformResult =
const expectedInvariantTransformResult =
'!condition ? ' +
'__DEV__ ? ' +
"invariant(false, 'Do not override existing functions.') : " +
Expand Down
6 changes: 3 additions & 3 deletions scripts/error-codes/replace-invariant-error-codes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
*/
'use strict';

var fs = require('fs');
var evalToString = require('../shared/evalToString');
var invertObject = require('./invertObject');
const fs = require('fs');
const evalToString = require('../shared/evalToString');
const invertObject = require('./invertObject');

module.exports = function(babel) {
const t = babel.types;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

'use strict';

var rule = require('../no-primitive-constructors');
var RuleTester = require('eslint').RuleTester;
var ruleTester = new RuleTester();
const rule = require('../no-primitive-constructors');
const RuleTester = require('eslint').RuleTester;
const ruleTester = new RuleTester();

ruleTester.run('eslint-rules/no-primitive-constructors', rule, {
valid: ['!!obj', "'' + obj", '+string'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

'use strict';

var rule = require('../warning-and-invariant-args');
var RuleTester = require('eslint').RuleTester;
var ruleTester = new RuleTester();
const rule = require('../warning-and-invariant-args');
const RuleTester = require('eslint').RuleTester;
const ruleTester = new RuleTester();

ruleTester.run('eslint-rules/warning-and-invariant-args', rule, {
valid: [
Expand Down
10 changes: 5 additions & 5 deletions scripts/eslint-rules/warning-and-invariant-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ module.exports = function(context) {
if (node.type === 'Literal' && typeof node.value === 'string') {
return node.value;
} else if (node.type === 'BinaryExpression' && node.operator === '+') {
var l = getLiteralString(node.left);
var r = getLiteralString(node.right);
const l = getLiteralString(node.left);
const r = getLiteralString(node.right);
if (l !== null && r !== null) {
return l + r;
}
Expand All @@ -33,7 +33,7 @@ module.exports = function(context) {
CallExpression: function(node) {
// This could be a little smarter by checking context.getScope() to see
// how warning/invariant was defined.
var isWarningOrInvariant =
const isWarningOrInvariant =
node.callee.type === 'Identifier' &&
(node.callee.name === 'warning' || node.callee.name === 'invariant');
if (!isWarningOrInvariant) {
Expand All @@ -45,7 +45,7 @@ module.exports = function(context) {
});
return;
}
var format = getLiteralString(node.arguments[1]);
const format = getLiteralString(node.arguments[1]);
if (format === null) {
context.report(
node,
Expand All @@ -64,7 +64,7 @@ module.exports = function(context) {
return;
}
// count the number of formatting substitutions, plus the first two args
var expectedNArgs = (format.match(/%s/g) || []).length + 2;
const expectedNArgs = (format.match(/%s/g) || []).length + 2;
if (node.arguments.length !== expectedNArgs) {
context.report(
node,
Expand Down
27 changes: 27 additions & 0 deletions scripts/eslint/eslintrc.node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

const eslintrc = require('../../.eslintrc');

const ERROR = 2;

module.exports = Object.assign({}, eslintrc, {
parser: 'espree',
parserOptions: {
ecmaVersion: 2017,
sourceType: 'script',
ecmaFeatures: {
experimentalObjectRestSpread: true,
},
},
rules: Object.assign({}, eslintrc.rules, {
'no-var': ERROR,
strict: ERROR,
}),
});
18 changes: 18 additions & 0 deletions scripts/eslint/eslintrc.npm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

const eslintrc = require('../../.eslintrc');

module.exports = Object.assign({}, eslintrc, {
parser: 'espree',
parserOptions: {
ecmaVersion: 5,
sourceType: 'script',
},
});
18 changes: 18 additions & 0 deletions scripts/eslint/eslintrc.source.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

const eslintrc = require('../../.eslintrc');

const ERROR = 2;

module.exports = Object.assign({}, eslintrc, {
rules: Object.assign({}, eslintrc.rules, {
'no-var': ERROR,
}),
});
50 changes: 46 additions & 4 deletions scripts/eslint/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,54 @@
'use strict';

const CLIEngine = require('eslint').CLIEngine;
const cli = new CLIEngine();
const formatter = cli.getFormatter();
const {npmPath, nodePath, sourcePath} = require('../shared/esPath');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s rename that file to filesByLanguageVersion?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok


module.exports = function lintOnFiles(filePatterns) {
const npmOptions = {
configFile: `${__dirname}/eslintrc.npm.js`,
ignorePattern: [...nodePath, ...sourcePath],
};

const nodeOptions = {
configFile: `${__dirname}/eslintrc.node.js`,
ignorePattern: [...npmPath, ...sourcePath],
};

const sourceOptions = {
configFile: `${__dirname}/eslintrc.source.js`,
ignorePattern: [...npmPath, ...nodePath],
};

module.exports = function lintOnFiles({ecmaVersion, filePatterns}) {
let options;
switch (ecmaVersion) {
case '5':
options = npmOptions;
break;
case '6':
options = nodeOptions;
break;
case 'next':
options = sourceOptions;
break;
default:
console.error('ecmaVersion only accpet value: "5", "6", "next"');
}

const cli = new CLIEngine({...options});
const formatter = cli.getFormatter();
const report = cli.executeOnFiles(filePatterns);
const formattedResults = formatter(report.results);

// When using `ignorePattern`, eslint will show `File ignored...` warning message when match ignore file.
// Currently, the only way to turn off this warning message is to set quiet = true.
// But it will remove `all warnings`, it's not appropriate to turn off other warning message
// So that's why we filter out the ignore pattern message.
// related issue: https://github.com/eslint/eslint/issues/5623
const filteredReport = report.results.filter(item => {
const ignoreMessage =
'File ignored because of a matching ignore pattern. Use "--no-ignore" to override.';
return !(item.messages[0] && item.messages[0].message === ignoreMessage);
});
const formattedResults = formatter(filteredReport);
console.log(formattedResults);
return report;
};
Loading