diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..5a51806d --- /dev/null +++ b/.editorconfig @@ -0,0 +1,10 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true +charset = utf-8 +indent_size = 2 +indent_style = space +trim_trailing_whitespace = true + diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..25439044 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,2 @@ +**/node_modules +build/ diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 00000000..990b19eb --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,186 @@ +const restrictedGlobals = require('confusing-browser-globals'); + +const OFF = 0; +const ERROR = 2; + +module.exports = { + extends: ['fbjs', 'prettier'], + + // Stop ESLint from looking for a configuration file in parent folders + root: true, + + plugins: [ + 'jest', + 'no-for-of-loops', + 'no-function-declare-after-return', + 'react', + ], + + parser: 'babel-eslint', + parserOptions: { + ecmaVersion: 8, + sourceType: 'module', + ecmaFeatures: { + experimentalObjectRestSpread: true, + }, + }, + env: { + 'mocha': true, + 'node': true, + }, + + // We're stricter than the default config, mostly. We'll override a few rules + // and then enable some React specific ones. + rules: { + 'accessor-pairs': OFF, + 'brace-style': [ERROR, '1tbs'], + 'consistent-return': OFF, + 'dot-location': [ERROR, 'property'], + // We use console['error']() as a signal to not transform it: + 'dot-notation': [ERROR, {allowPattern: '^(error|warn)$'}], + 'eol-last': ERROR, + eqeqeq: [ERROR, 'allow-null'], + indent: OFF, + 'jsx-quotes': [ERROR, 'prefer-double'], + 'keyword-spacing': [ERROR, {after: true, before: true}], + 'no-bitwise': OFF, + 'no-inner-declarations': [ERROR, 'functions'], + 'no-multi-spaces': ERROR, + 'no-restricted-globals': [ERROR].concat(restrictedGlobals), + 'no-restricted-syntax': [ERROR, 'WithStatement'], + 'no-shadow': ERROR, + 'no-unused-expressions': ERROR, + 'no-unused-vars': [ERROR, {args: 'none'}], + 'no-use-before-define': OFF, + 'no-useless-concat': OFF, + quotes: [ERROR, 'single', {avoidEscape: true, allowTemplateLiterals: true}], + 'space-before-blocks': ERROR, + 'space-before-function-paren': OFF, + 'valid-typeof': [ERROR, {requireStringLiterals: true}], + + // We apply these settings to files that should run on Node. + // They can't use JSX or ES6 modules, and must be in strict mode. + // They can, however, use other ES6 features. + // (Note these rules are overridden later for source files.) + 'no-var': ERROR, + strict: ERROR, + + // Enforced by Prettier + // TODO: Prettier doesn't handle long strings or long comments. Not a big + // deal. But I turned it off because loading the plugin causes some obscure + // syntax error and it didn't seem worth investigating. + 'max-len': OFF, + + // React & JSX + // Our transforms set this automatically + 'react/jsx-boolean-value': [ERROR, 'always'], + 'react/jsx-no-undef': ERROR, + // We don't care to do this + 'react/jsx-sort-prop-types': OFF, + 'react/jsx-space-before-closing': ERROR, + 'react/jsx-uses-react': ERROR, + 'react/no-is-mounted': OFF, + // This isn't useful in our test code + 'react/react-in-jsx-scope': ERROR, + 'react/self-closing-comp': ERROR, + // We don't care to do this + 'react/jsx-wrap-multilines': [ + ERROR, + {declaration: false, assignment: false}, + ], + + // Prevent for...of loops because they require a Symbol polyfill. + // You can disable this rule for code that isn't shipped (e.g. build scripts and tests). + 'no-for-of-loops/no-for-of-loops': ERROR, + + // Prevent function declarations after return statements + 'no-function-declare-after-return/no-function-declare-after-return': ERROR, + }, + + overrides: [ + { + // We apply these settings to the source files that get compiled. + // They can use all features including JSX (but shouldn't use `var`). + files: [ + // Internal forwarding modules + 'libs/*/*.js', + // Source files + 'libs/*/src/**/*.js', + ], + parser: 'babel-eslint', + parserOptions: { + ecmaVersion: 8, + sourceType: 'module', + }, + rules: { + 'no-var': ERROR, + 'prefer-const': ERROR, + strict: OFF, + }, + }, + { + files: ['**/__tests__/*.js'], + rules: { + // https://github.com/jest-community/eslint-plugin-jest + 'jest/no-focused-tests': ERROR, + 'jest/valid-expect': ERROR, + 'jest/valid-expect-in-promise': ERROR, + }, + }, + { + files: [ + '**/__tests__/**/*.js', + 'scripts/**/*.js', + 'libs/*/npm/**/*.js', + 'libs/dom-event-testing-library/**/*.js', + 'libs/react-devtools*/**/*.js', + ], + rules: { + 'react-internal/no-production-logging': OFF, + 'react-internal/warning-args': OFF, + }, + }, + { + files: ['libs/react-native-renderer/**/*.js'], + globals: { + nativeFabricUIManager: true, + }, + }, + { + files: ['libs/react-transport-dom-webpack/**/*.js'], + globals: { + __webpack_chunk_load__: true, + __webpack_require__: true, + }, + }, + { + files: ['libs/scheduler/**/*.js'], + globals: { + TaskController: true, + }, + }, + { + files: [ + 'scripts/e2e-test/**/*.js', + 'scripts/e2e-test/**/*.jsx', + ], + parserOptions: { + sourceType: 'module', + }, + } + ], + + globals: { + SharedArrayBuffer: true, + + spyOnDev: true, + spyOnDevAndProd: true, + spyOnProd: true, + __PROFILE__: true, + __UMD__: true, + __EXPERIMENTAL__: true, + __VARIANT__: true, + gate: true, + trustedTypes: true, + }, +}; diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..7c699172 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +node_modules +build/ +.idea +.vscode +package-lock.json diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 00000000..394ae9ab --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1,17 @@ +'use strict'; + +module.exports = { + printWidth: 120, // 一行120字符数,如果超过会进行换行 + tabWidth: 2, // tab等2个空格 + useTabs: false, // 用空格缩进行 + semi: true, // 行尾使用分号 + singleQuote: true, // 字符串使用单引号 + quoteProps: 'as-needed', // 仅在需要时在对象属性添加引号 + jsxSingleQuote: false, // 在JSX中使用双引号 + trailingComma: 'es5', // 使用尾逗号(对象、数组等) + bracketSpacing: true, // 对象的括号间增加空格 + jsxBracketSameLine: false, // 将多行JSX元素的>放在最后一行的末尾 + arrowParens: 'avoid', // 在唯一的arrow函数参数周围省略括号 + vueIndentScriptAndStyle: false, // 不缩进Vue文件中的