From 59cfe85cca9a836234da0537138302f261373fdd Mon Sep 17 00:00:00 2001 From: Rafael Oleza Date: Thu, 1 Mar 2018 05:38:58 -0800 Subject: [PATCH] Make eslint rules more strict Reviewed By: cpojer Differential Revision: D7123137 fbshipit-source-id: 68f82124ed565f223c6bf546c22e55ca401f1996 --- .eslintrc.js | 6 +++-- .../src/__tests__/index-test.js | 24 ++++++++++++------- scripts/watch.js | 2 ++ 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 5b4dbd01..24bc9c33 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -16,11 +16,13 @@ module.exports = { plugins: ['babel', 'flowtype', 'import', 'prettier'], parser: 'babel-eslint', rules: { + 'consistent-return': 'error', 'import/no-extraneous-dependencies': 'error', 'lint/extra-arrow-initializer': 'off', 'max-len': 'off', - 'no-alert': 'off', - 'no-console-disallow': 'off', + 'no-alert': 'error', + 'no-console': 'error', + 'no-unused-vars': 'error', 'no-var': 'off', 'prefer-arrow-callback': 'off', 'prefer-const': ['warn', {destructuring: 'all'}], diff --git a/packages/metro-memory-fs/src/__tests__/index-test.js b/packages/metro-memory-fs/src/__tests__/index-test.js index 6ab9153d..0d357108 100644 --- a/packages/metro-memory-fs/src/__tests__/index-test.js +++ b/packages/metro-memory-fs/src/__tests__/index-test.js @@ -38,11 +38,13 @@ it('works without binding functions', () => { it('can write then read a file (async)', done => { fs.writeFile('/foo.txt', 'test', wrError => { if (wrError) { - return done(wrError); + done(wrError); + return; } fs.readFile('/foo.txt', 'utf8', (rdError, str) => { if (rdError) { - return done(rdError); + done(rdError); + return; } expect(str).toEqual('test'); done(); @@ -57,8 +59,9 @@ it('can write then read a file as buffer', () => { it('can write a file with a stream', done => { const st = fs.createWriteStream('/foo.txt'); - let opened = false, - closed = false; + let opened = false; + let closed = false; + st.on('open', () => (opened = true)); st.on('close', () => (closed = true)); st.write('test'); @@ -73,8 +76,9 @@ it('can write a file with a stream', done => { it('can write a file with a stream, as buffer', done => { const st = fs.createWriteStream('/foo.txt'); - let opened = false, - closed = false; + let opened = false; + let closed = false; + st.on('open', () => (opened = true)); st.on('close', () => (closed = true)); st.write(Buffer.from('test')); @@ -90,8 +94,9 @@ it('can write a file with a stream, as buffer', done => { it('can write a file with a stream, with a starting position', done => { fs.writeFileSync('/foo.txt', 'test bar'); const st = fs.createWriteStream('/foo.txt', {start: 5, flags: 'r+'}); - let opened = false, - closed = false; + let opened = false; + let closed = false; + st.on('open', () => (opened = true)); st.on('close', () => (closed = true)); st.write('beep'); @@ -217,7 +222,8 @@ it('throws when trying to read a directory entry', () => { it('throws when trying to read inexistent file (async)', done => { fs.readFile('/foo.txt', error => { if (error.code !== 'ENOENT') { - return done(error); + done(error); + return; } expect(error.message).toMatchSnapshot(); done(); diff --git a/scripts/watch.js b/scripts/watch.js index bd952b6b..ad81125d 100644 --- a/scripts/watch.js +++ b/scripts/watch.js @@ -39,6 +39,7 @@ getPackages().forEach(p => { const filePath = path.resolve(srcDir, filename); if ((event === 'change' || event === 'rename') && exists(filePath)) { + // eslint-disable-next-line no-console console.log(chalk.green('->'), `${event}: ${filename}`); rebuild(filePath); } else { @@ -69,4 +70,5 @@ setInterval(() => { } }, 100); +// eslint-disable-next-line no-console console.log(chalk.red('->'), chalk.cyan('Watching for changes...'));