Skip to content

Commit

Permalink
chore: use @react-native-community/eslint-config (react-native-commun…
Browse files Browse the repository at this point in the history
…ity#205)

Summary:
---------

I changed @callstack/eslint-config to @react-native-community/eslint-config and fixed all lint issues.


Test Plan:
----------

Green CI
  • Loading branch information
dratwas authored and thymikee committed Mar 5, 2019
1 parent 8ef2a97 commit 885f2c2
Show file tree
Hide file tree
Showing 168 changed files with 820 additions and 1,004 deletions.
7 changes: 2 additions & 5 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ module.exports = {
[
require.resolve('@babel/preset-env'),
{
targets: { node: 8 },
targets: {node: 8},
useBuiltIns: 'entry',
},
],
require.resolve('@babel/preset-flow'),
],
plugins: [
require.resolve('@babel/plugin-transform-strict-mode'),
[
require.resolve('@babel/plugin-transform-modules-commonjs'),
{ lazy: true },
],
[require.resolve('@babel/plugin-transform-modules-commonjs'), {lazy: true}],
],
};
18 changes: 6 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,26 @@
"@babel/plugin-transform-strict-mode": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/preset-flow": "^7.0.0",
"@callstack/eslint-config": "^3.0.2",
"@react-native-community/eslint-config": "^0.0.2",
"babel-jest": "^24.0.0",
"chalk": "^2.4.2",
"eslint": "^5.10.0",
"eslint-plugin-prettier": "^3.0.1",
"flow-bin": "^0.94.0",
"glob": "^7.1.3",
"jest": "^24.0.0",
"lerna": "^3.10.6",
"micromatch": "^3.1.10",
"mkdirp": "^0.5.1",
"prettier": "^1.16.0",
"string-length": "^2.0.0"
},
"eslintConfig": {
"extends": "@callstack",
"rules": {
"global-require": 0,
"no-console": 0
"extends": "@react-native-community",
"env": {
"es6": true,
"jest": true,
"node": true
}
},
"prettier": {
"proseWrap": "never",
"singleQuote": true,
"trailingComma": "es5"
},
"jest": {
"projects": [
"packages/*"
Expand Down
12 changes: 6 additions & 6 deletions packages/cli/src/__mocks__/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let fs;
function setMockFilesystem(object, platform) {
reset(platform);
const root = platform === 'win32' ? 'c:\\' : '/';
mockDir(root, { ...object });
mockDir(root, {...object});
return root;
}

Expand All @@ -24,14 +24,14 @@ function mockDir(dirPath, desc) {
const entPath = path.join(dirPath, entName);
if (typeof ent === 'string' || ent instanceof Buffer) {
fs.writeFileSync(entPath, ent);
continue; // eslint-disable-line no-continue
continue;
}
if (typeof ent !== 'object') {
throw new Error(util.format('invalid entity:', ent));
}
if (ent.SYMLINK != null) {
fs.symlinkSync(ent.SYMLINK, entPath);
continue; // eslint-disable-line no-continue
continue;
}
fs.mkdirSync(entPath);
mockDir(entPath, ent);
Expand All @@ -41,18 +41,18 @@ function mockDir(dirPath, desc) {
function reset(platform) {
if (path.mock == null) {
throw new Error(
'to use this "fs" module mock, you must also mock the "path" module'
'to use this "fs" module mock, you must also mock the "path" module',
);
}
path.mock.reset(platform);
const cwd = () => (platform === 'win32' ? 'c:\\' : '/');
fs = new MemoryFS({ platform, cwd });
fs = new MemoryFS({platform, cwd});
Object.assign(mockFs, fs);
}

const mockFs = {};
mockFs.__setMockFilesystem = setMockFilesystem;
mockFs.mock = { clear: reset };
mockFs.mock = {clear: reset};

reset('posix');

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/__mocks__/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function reset(platform) {
Object.assign(mockPath, jest.requireActual('path')[platform]);
}

mockPath.mock = { reset };
mockPath.mock = {reset};

reset('posix');

Expand Down
24 changes: 12 additions & 12 deletions packages/cli/src/cliEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import childProcess from 'child_process';
import commander from 'commander';
import minimist from 'minimist';
import path from 'path';
import type { CommandT, ContextT } from './tools/types.flow';
import type {CommandT, ContextT} from './tools/types.flow';
import getLegacyConfig from './tools/getLegacyConfig';
import { getCommands } from './commands';
import {getCommands} from './commands';
import init from './commands/init/init';
import assertRequiredOptions from './tools/assertRequiredOptions';
import logger from './tools/logger';
Expand Down Expand Up @@ -81,8 +81,8 @@ function printUnknownCommand(cmdName) {
logger.error(`Unrecognized command "${chalk.bold(cmdName)}".`);
logger.info(
`Run ${chalk.bold(
'"react-native --help"'
)} to see a list of all available commands.`
'"react-native --help"',
)} to see a list of all available commands.`,
);
} else {
commander.outputHelp();
Expand Down Expand Up @@ -119,8 +119,8 @@ const addCommand = (command: CommandT, ctx: ContextT) => {
opt.command,
opt.description,
opt.parse || defaultOptParser,
opt.default
)
opt.default,
),
);

// Redefined here to appear in the `--help` section
Expand All @@ -144,15 +144,15 @@ async function setupAndRun() {
const absolutePath = path.join(__dirname, '..', scriptName);

try {
childProcess.execFileSync(absolutePath, { stdio: 'pipe' });
childProcess.execFileSync(absolutePath, {stdio: 'pipe'});
} catch (error) {
logger.warn(
`Failed to run environment setup script "${scriptName}"\n\n${chalk.red(
error
)}`
error,
)}`,
);
logger.info(
`React Native CLI will continue to run if your local environment matches what React Native expects. If it does fail, check out "${absolutePath}" and adjust your environment to match it.`
`React Native CLI will continue to run if your local environment matches what React Native expects. If it does fail, check out "${absolutePath}" and adjust your environment to match it.`,
);
}
}
Expand All @@ -177,11 +177,11 @@ async function setupAndRun() {
// $FlowIssue: Wrong `require.resolve` type definition
require.resolve('react-native/package.json', {
paths: [root],
})
}),
);
} catch (_ignored) {
throw new Error(
'Unable to find React Native files. Make sure "react-native" module is installed in your project dependencies.'
'Unable to find React Native files. Make sure "react-native" module is installed in your project dependencies.',
);
}
})();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('getAssetDestPathAndroid', () => {
const expectDestPathForScaleToStartWith = (scale, location) => {
if (!getAssetDestPathAndroid(asset, scale).startsWith(location)) {
throw new Error(
`asset for scale ${scale} should start with path '${location}'`
`asset for scale ${scale} should start with path '${location}'`,
);
}
};
Expand All @@ -45,7 +45,7 @@ describe('getAssetDestPathAndroid', () => {
};

expect(getAssetDestPathAndroid(asset, 1)).toBe(
path.normalize('drawable-mdpi/app_test_icon.png')
path.normalize('drawable-mdpi/app_test_icon.png'),
);
});

Expand All @@ -67,7 +67,7 @@ describe('getAssetDestPathAndroid', () => {
};

expect(getAssetDestPathAndroid(asset, 1)).toBe(
path.normalize('raw/app_test_video.mp4')
path.normalize('raw/app_test_video.mp4'),
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('getAssetDestPathIOS', () => {
};

expect(getAssetDestPathIOS(asset, 1)).toBe(
path.normalize('assets/test/icon.png')
path.normalize('assets/test/icon.png'),
);
});

Expand All @@ -35,10 +35,10 @@ describe('getAssetDestPathIOS', () => {
};

expect(getAssetDestPathIOS(asset, 2)).toBe(
path.normalize('assets/test/[email protected]')
path.normalize('assets/test/[email protected]'),
);
expect(getAssetDestPathIOS(asset, 3)).toBe(
path.normalize('assets/test/[email protected]')
path.normalize('assets/test/[email protected]'),
);
});
});
4 changes: 2 additions & 2 deletions packages/cli/src/commands/bundle/assetPathUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ function getAndroidResourceFolderName(asset: PackagerAsset, scale: number) {
if (!suffix) {
throw new Error(
`Don't know which android drawable suffix to use for asset: ${JSON.stringify(
asset
)}`
asset,
)}`,
);
}
const androidFolder = `drawable-${suffix}`;
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/commands/bundle/buildBundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ import Server from 'metro/src/Server';

import outputBundle from 'metro/src/shared/output/bundle';
import path from 'path';
import type { CommandLineArgs } from './bundleCommandLineArgs';
import type { ContextT } from '../../tools/types.flow';
import type {CommandLineArgs} from './bundleCommandLineArgs';
import type {ContextT} from '../../tools/types.flow';
import saveAssets from './saveAssets';
import loadMetroConfig from '../../tools/loadMetroConfig';
import logger from '../../tools/logger';

async function buildBundle(
args: CommandLineArgs,
ctx: ContextT,
output: typeof outputBundle = outputBundle
output: typeof outputBundle = outputBundle,
) {
const config = await loadMetroConfig(ctx, {
resetCache: args.resetCache,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/bundle/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ export default {

const withOutput = bundleWithOutput;

export { withOutput };
export {withOutput};
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const ALLOWED_SCALES = {

function filterPlatformAssetScales(
platform: string,
scales: $ReadOnlyArray<number>
scales: $ReadOnlyArray<number>,
): $ReadOnlyArray<number> {
const whitelist = ALLOWED_SCALES[platform];
if (!whitelist) {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/bundle/getAssetDestPathAndroid.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
*/

import path from 'path';
import type { PackagerAsset } from './assetPathUtils';
import type {PackagerAsset} from './assetPathUtils';

import assetPathUtils from './assetPathUtils';

function getAssetDestPathAndroid(asset: PackagerAsset, scale: number): string {
const androidFolder = assetPathUtils.getAndroidResourceFolderName(
asset,
scale
scale,
);
const fileName = assetPathUtils.getAndroidResourceIdentifier(asset);
return path.join(androidFolder, `${fileName}.${asset.type}`);
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/bundle/getAssetDestPathIOS.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/

import path from 'path';
import type { PackagerAsset } from './assetPathUtils';
import type {PackagerAsset} from './assetPathUtils';

function getAssetDestPathIOS(asset: PackagerAsset, scale: number): string {
const suffix = scale === 1 ? '' : `@${scale}x`;
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/bundle/ramBundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
import outputUnbundle from 'metro/src/shared/output/RamBundle';

import { withOutput as bundleWithOutput } from './bundle';
import {withOutput as bundleWithOutput} from './bundle';
import bundleCommandLineArgs from './bundleCommandLineArgs';

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/bundle/saveAssets.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function saveAssets(assets, platform, assetsDest) {
const filesToCopy = Object.create(null); // Map src -> dest
assets.forEach(asset => {
const validScales = new Set(
filterPlatformAssetScales(platform, asset.scales)
filterPlatformAssetScales(platform, asset.scales),
);
asset.scales.forEach((scale, idx) => {
if (!validScales.has(scale)) {
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/commands/dependencies/dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ async function dependencies(argv, configPromise, args, packagerInstance) {
const config = await configPromise;
if (!fs.existsSync(rootModuleAbsolutePath)) {
return Promise.reject(
new Error(`File ${rootModuleAbsolutePath} does not exist`)
new Error(`File ${rootModuleAbsolutePath} does not exist`),
);
}

config.cacheStores = [];

const relativePath = path.relative(
config.projectRoot,
rootModuleAbsolutePath
rootModuleAbsolutePath,
);

const options = {
Expand Down Expand Up @@ -69,7 +69,7 @@ export default {
description: 'lists dependencies',
func: util.deprecate(
dependencies,
'dependencies command was moved to metro, and will be removed from cli in next release'
'dependencies command was moved to metro, and will be removed from cli in next release',
),
options: [
{
Expand Down
Loading

0 comments on commit 885f2c2

Please sign in to comment.