mirror of
https://github.com/facebook/react.git
synced 2026-02-27 03:07:57 +00:00
* [WIP] Table of attribute behavior * getAttribute helper * add getters for attributes V-Z * More special cases * Add getters for more attributes * Add tagName to attribute config * Switch default accessor to getProperty instead of getAttribute * Add containerTagName and tagName config * Compare result to default value * Add overrideStringValue config option * add section for Sebastian and update a couple more attributes * 'array with string' should use string override, too * Add additional value types Strings on, off, true, false * more attribute updates * More attributes * Remove old directory * add more attribute configs * More attributes * just a couple more attribute updates * More attributes * Fix the seb parts * Fix the seb parts # Conflicts: # scripts/attribute-behavior/src/App.js * More attributes * Prettier * More attributes * More attributes * Fix some bugs in seb's set * Fix the rest of flarnie's section * More attributes * Prettier * Finish my section (Andrew) * Compare against UMD build of master Once we get past MVP stage we can hook this up to the build system so these files are automatically copied over. * Fix attributes that don't have compatible properties Avoid all undefined reads. * Test multiple input types Tests different input types and valueAsNumber property. This value is often NaN. To compare that we also need to switch to Object.is. * Ignore checked in copies of React 15 bundles in attribute fixture **what is the change?:** We checked in bundles of React v15 to run comparisons of attribute behavior on DOM elements between 15 and 16. This commit tells prettier and eslint to ignore those files, and fixes a prettier lint in one other file from that fixture. **why make this change?:** To get CI passing. **test plan:** `yarn prettier` doesn't change anything, eslint passes **issue:** * update README for attribute table fixture * run prettier again
116 lines
3.1 KiB
JavaScript
116 lines
3.1 KiB
JavaScript
/**
|
|
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*/
|
|
'use strict';
|
|
|
|
// Based on similar script in Jest
|
|
// https://github.com/facebook/jest/blob/master/scripts/prettier.js
|
|
|
|
const chalk = require('chalk');
|
|
const glob = require('glob');
|
|
const path = require('path');
|
|
const execFileSync = require('child_process').execFileSync;
|
|
|
|
const mode = process.argv[2] || 'check';
|
|
const shouldWrite = mode === 'write' || mode === 'write-changed';
|
|
const onlyChanged = mode === 'check-changed' || mode === 'write-changed';
|
|
|
|
const isWindows = process.platform === 'win32';
|
|
const prettier = isWindows ? 'prettier.cmd' : 'prettier';
|
|
const prettierCmd = path.resolve(
|
|
__dirname,
|
|
'../../node_modules/.bin/' + prettier
|
|
);
|
|
const defaultOptions = {
|
|
'bracket-spacing': 'false',
|
|
'single-quote': 'true',
|
|
'jsx-bracket-same-line': 'true',
|
|
'trailing-comma': 'all',
|
|
'print-width': 80,
|
|
};
|
|
const config = {
|
|
default: {
|
|
patterns: ['src/**/*.js'],
|
|
ignore: ['**/third_party/**', '**/node_modules/**'],
|
|
},
|
|
scripts: {
|
|
patterns: ['scripts/**/*.js', 'fixtures/**/*.js'],
|
|
ignore: [
|
|
'scripts/bench/benchmarks/**',
|
|
'scripts/attribute-behavior/public/react.production.min.js',
|
|
'scripts/attribute-behavior/public/react-dom.production.min.js',
|
|
],
|
|
options: {
|
|
'trailing-comma': 'es5',
|
|
},
|
|
},
|
|
};
|
|
|
|
function exec(command, args) {
|
|
console.log('> ' + [command].concat(args).join(' '));
|
|
var options = {
|
|
cwd: process.cwd(),
|
|
env: process.env,
|
|
stdio: 'pipe',
|
|
encoding: 'utf-8',
|
|
};
|
|
return execFileSync(command, args, options);
|
|
}
|
|
|
|
var mergeBase = exec('git', ['merge-base', 'HEAD', 'master']).trim();
|
|
var changedFiles = new Set(
|
|
exec('git', [
|
|
'diff',
|
|
'-z',
|
|
'--name-only',
|
|
'--diff-filter=ACMRTUB',
|
|
mergeBase,
|
|
]).match(/[^\0]+/g)
|
|
);
|
|
|
|
Object.keys(config).forEach(key => {
|
|
const patterns = config[key].patterns;
|
|
const options = config[key].options;
|
|
const ignore = config[key].ignore;
|
|
|
|
const globPattern = patterns.length > 1
|
|
? `{${patterns.join(',')}}`
|
|
: `${patterns.join(',')}`;
|
|
const files = glob
|
|
.sync(globPattern, {ignore})
|
|
.filter(f => !onlyChanged || changedFiles.has(f));
|
|
|
|
if (!files.length) {
|
|
return;
|
|
}
|
|
|
|
const args = Object.keys(defaultOptions).map(
|
|
k => `--${k}=${(options && options[k]) || defaultOptions[k]}`
|
|
);
|
|
args.push(`--${shouldWrite ? 'write' : 'l'}`);
|
|
|
|
try {
|
|
exec(prettierCmd, [...args, ...files]).trim();
|
|
} catch (e) {
|
|
if (!shouldWrite) {
|
|
console.log(
|
|
'\n' +
|
|
chalk.red(
|
|
` This project uses prettier to format all JavaScript code.\n`
|
|
) +
|
|
chalk.dim(` Please run `) +
|
|
chalk.reset('yarn prettier-all') +
|
|
chalk.dim(` and add changes to files listed below to your commit:`) +
|
|
`\n\n` +
|
|
e.stdout
|
|
);
|
|
process.exit(1);
|
|
}
|
|
throw e;
|
|
}
|
|
});
|