Skip to content

Commit

Permalink
chore: add eslint-plugin-eslint-comments (#9229)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Nov 24, 2019
1 parent 6f9bbf5 commit 429877d
Show file tree
Hide file tree
Showing 30 changed files with 91 additions and 50 deletions.
17 changes: 15 additions & 2 deletions .eslintrc.js
Expand Up @@ -12,6 +12,7 @@ module.exports = {
'plugin:import/typescript',
'prettier',
'prettier/flowtype',
'plugin:eslint-comments/recommended',
],
overrides: [
{
Expand Down Expand Up @@ -67,11 +68,23 @@ module.exports = {
},
},
{
files: ['packages/jest-types/**/*'],
files: 'packages/jest-types/**/*',
rules: {
'import/no-extraneous-dependencies': 0,
},
},
{
files: [
'packages/jest-jasmine2/src/jasmine/**/*',
'packages/expect/src/jasmineUtils.ts',
'e2e/browser-support/browserTest.js',
'**/vendor/**/*',
],
rules: {
'eslint-comments/disable-enable-pair': 0,
'eslint-comments/no-unlimited-disable': 0,
},
},
{
files: [
'website/**',
Expand All @@ -85,7 +98,7 @@ module.exports = {
},
],
parser: 'babel-eslint',
plugins: ['markdown', 'import', 'prettier'],
plugins: ['markdown', 'import', 'prettier', 'eslint-comments'],
rules: {
'arrow-body-style': 2,
'flowtype/boolean-style': 2,
Expand Down
Expand Up @@ -14,22 +14,22 @@ Object {
"decl": Object {
"end": Object {
"column": 36,
"line": 9,
"line": 8,
},
"start": Object {
"column": 26,
"line": 9,
"line": 8,
},
},
"line": 9,
"line": 8,
"loc": Object {
"end": Object {
"column": 1,
"line": 12,
},
"start": Object {
"column": 58,
"line": 9,
"line": 8,
},
},
"name": "doES6Stuff",
Expand All @@ -49,7 +49,7 @@ Object {
},
"start": Object {
"column": 0,
"line": 9,
"line": 8,
},
},
"1": Object {
Expand Down
3 changes: 2 additions & 1 deletion e2e/__tests__/iterator-to-null-test.ts
Expand Up @@ -4,11 +4,12 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/* eslint-disable no-extend-native */

'use strict';

/* eslint-disable no-extend-native */
Array.prototype[Symbol.iterator] = null;
String.prototype[Symbol.iterator] = null;
/* eslint-enable */

test('modifying global object does not affect test runner', () => {});
3 changes: 1 addition & 2 deletions e2e/babel-plugin-jest-hoist/__tests__/integration.test.js
Expand Up @@ -6,8 +6,6 @@
*
*/

/* eslint-disable no-useless-concat */

'use strict';

import React from 'react';
Expand Down Expand Up @@ -53,6 +51,7 @@ jest.mock('has-flow-types', () => (props: {children: mixed}) => 3, {

// These will not be hoisted
jest.unmock('../__test_modules__/a').dontMock('../__test_modules__/b');
// eslint-disable-next-line no-useless-concat
jest.unmock('../__test_modules__/' + 'c');
jest.dontMock('../__test_modules__/Mocked');

Expand Down
2 changes: 2 additions & 0 deletions e2e/coverage-remapping/covered.ts
Expand Up @@ -15,3 +15,5 @@ export = function difference(a: number, b: number): number {

return a - b;
};

/* eslint-enable */
2 changes: 1 addition & 1 deletion e2e/coverage-report/notRequiredInTestSuite.js
Expand Up @@ -11,7 +11,7 @@ throw new Error(
);

// Flow annotations to make sure istanbul can instrument non ES6 source
/* eslint-disable no-unreachable */
// eslint-disable-next-line no-unreachable
module.exports = function(j: string, d: string): string {
if (j) {
return d;
Expand Down
2 changes: 1 addition & 1 deletion e2e/coverage-transform-instrumented/covered.js
@@ -1,4 +1,3 @@
/* eslint-disable no-unused-vars */
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
Expand All @@ -7,6 +6,7 @@
*/

module.exports = function doES6Stuff(testObj, multiplier) {
// eslint-disable-next-line no-unused-vars
const {someNumber, ...others} = testObj;
return someNumber * multiplier;
};
3 changes: 1 addition & 2 deletions e2e/each/__tests__/describeOnly.test.js
Expand Up @@ -5,8 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

/* eslint-disable jest/no-focused-tests */

// eslint-disable-next-line jest/no-focused-tests
describe.only.each([
[true, true],
[true, true],
Expand Down
4 changes: 2 additions & 2 deletions e2e/each/__tests__/eachOnly.test.js
Expand Up @@ -5,8 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

/* eslint-disable jest/no-focused-tests */

// eslint-disable-next-line jest/no-focused-tests
it.only.each([
[true, true],
[true, true],
Expand All @@ -21,6 +20,7 @@ it.each([
expect(left).toBe(right);
});

// eslint-disable-next-line jest/no-focused-tests
it.only.each`
left | right
${true} | ${true}
Expand Down
2 changes: 1 addition & 1 deletion e2e/failures/__tests__/throwNumber.test.js
Expand Up @@ -7,5 +7,5 @@

'use strict';

/* eslint-disable no-throw-literal */
// eslint-disable-next-line no-throw-literal
throw 1;
2 changes: 1 addition & 1 deletion e2e/failures/__tests__/throwObject.test.js
Expand Up @@ -7,5 +7,5 @@

'use strict';

/* eslint-disable no-throw-literal */
// eslint-disable-next-line no-throw-literal
throw {};
2 changes: 1 addition & 1 deletion e2e/failures/__tests__/throwString.test.js
Expand Up @@ -7,5 +7,5 @@

'use strict';

/* eslint-disable no-throw-literal */
// eslint-disable-next-line no-throw-literal
throw 'banana';
2 changes: 2 additions & 0 deletions e2e/focused-tests/__tests__/tests.js
Expand Up @@ -23,3 +23,5 @@ describe.only('describe only', () => {
expect(1).toBe(1);
});
});

/* eslint-enable */
3 changes: 2 additions & 1 deletion e2e/jasmine-async/__tests__/promiseBeforeAll.test.js
Expand Up @@ -35,7 +35,8 @@ describe('promise beforeAll', () => {
describe('done - with error thrown', () => {
beforeAll(done => {
throw new Error('fail');
done(); // eslint-disable-line
// eslint-disable-next-line no-unreachable
done();
});
it('fails', () => {});
});
Expand Down
3 changes: 2 additions & 1 deletion e2e/jasmine-async/__tests__/promiseBeforeEach.test.js
Expand Up @@ -25,7 +25,8 @@ describe('promise beforeEach', () => {
describe('done - with error thrown', () => {
beforeEach(done => {
throw new Error('fail');
done(); // eslint-disable-line
// eslint-disable-next-line no-unreachable
done();
});
it('fails', () => {});
});
Expand Down
2 changes: 2 additions & 0 deletions e2e/jasmine-async/__tests__/promiseFit.test.js
Expand Up @@ -18,3 +18,5 @@ describe('promise fit', () => {

fit('will run and fail', () => Promise.reject());
});

/* eslint-enable */
6 changes: 4 additions & 2 deletions e2e/jasmine-async/__tests__/promiseIt.test.js
Expand Up @@ -63,13 +63,15 @@ describe('promise it', () => {

it('fails with thrown error with done - sync', done => {
throw new Error('sync fail');
done(); // eslint-disable-line
// eslint-disable-next-line no-unreachable
done();
});

it('fails with thrown error with done - async', done => {
setTimeout(() => {
throw new Error('async fail');
done(); // eslint-disable-line
// eslint-disable-next-line no-unreachable
done();
}, 1);
});

Expand Down
3 changes: 1 addition & 2 deletions e2e/snapshot-serializers/plugins/bar.js
Expand Up @@ -6,8 +6,7 @@
*
*/

/* eslint-disable no-unused-vars */

// eslint-disable-next-line no-unused-vars
const createPlugin = require('../utils').createPlugin;

// We inject the call to "createPlugin('bar') through the transformer"
2 changes: 1 addition & 1 deletion e2e/stack-trace/__tests__/runtimeError.test.js
Expand Up @@ -6,5 +6,5 @@
*/
'use strict';

/* eslint-disable no-undef */
// eslint-disable-next-line no-undef
thisIsARuntimeError();
2 changes: 1 addition & 1 deletion e2e/stack-trace/__tests__/testError.test.js
Expand Up @@ -4,7 +4,6 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/* eslint-disable no-throw-literal */
'use strict';

describe('error stack trace', () => {
Expand All @@ -13,6 +12,7 @@ describe('error stack trace', () => {
});

it('fails strings', () => {
// eslint-disable-next-line no-throw-literal
throw 'this is a string.';
});

Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -31,6 +31,7 @@
"eslint": "^6.2.2",
"eslint-config-prettier": "^6.1.0",
"eslint-plugin-babel": "^5.1.0",
"eslint-plugin-eslint-comments": "^3.1.2",
"eslint-plugin-flowtype": "^4.2.0",
"eslint-plugin-import": "^2.6.0",
"eslint-plugin-jest": "^23.0.2",
Expand Down Expand Up @@ -86,7 +87,7 @@
"clean-e2e": "find ./e2e -not \\( -path ./e2e/presets/js -prune \\) -not \\( -path ./e2e/presets/json -prune \\) -not \\( -path ./e2e/global-setup-node-modules -prune \\) -mindepth 1 -type d \\( -name node_modules -prune \\) -exec rm -r '{}' +",
"jest": "node ./packages/jest-cli/bin/jest.js",
"jest-coverage": "yarn jest --coverage",
"lint": "eslint . --cache --report-unused-disable-directives --ext js,jsx,ts,tsx,md",
"lint": "eslint . --cache --ext js,jsx,ts,tsx,md",
"lint-es5-build": "eslint --no-eslintrc --no-ignore --env=browser packages/*/build-es5",
"lint:prettier": "yarn --silent lint:prettier:ci --fix",
"lint:prettier:ci": "prettylint '**/*.{md,yml,yaml}' --ignore-path .gitignore",
Expand Down
10 changes: 4 additions & 6 deletions packages/diff-sequences/README.md
Expand Up @@ -34,9 +34,8 @@ To use `diff` as the name of the default export from this package, do either of
Call `diff` with the **lengths** of sequences and your **callback** functions:

```js
/* eslint-disable no-var */
var a = ['a', 'b', 'c', 'a', 'b', 'b', 'a'];
var b = ['c', 'b', 'a', 'b', 'a', 'c'];
const a = ['a', 'b', 'c', 'a', 'b', 'b', 'a'];
const b = ['c', 'b', 'a', 'b', 'a', 'c'];

function isCommon(aIndex, bIndex) {
return a[aIndex] === b[bIndex];
Expand Down Expand Up @@ -73,10 +72,9 @@ Various packages which implement the Myers algorithm will **always agree** on th
## Example of callback functions to count common items

```js
/* eslint-disable no-var */
// Return length of longest common subsequence according to === operator.
function countCommonItems(a, b) {
var n = 0;
let n = 0;
function isCommon(aIndex, bIndex) {
return a[aIndex] === b[bIndex];
}
Expand All @@ -89,7 +87,7 @@ function countCommonItems(a, b) {
return n;
}

var commonLength = countCommonItems(
const commonLength = countCommonItems(
['a', 'b', 'c', 'a', 'b', 'b', 'a'],
['c', 'b', 'a', 'b', 'a', 'c'],
);
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-cli/src/init/__tests__/init.test.js
Expand Up @@ -177,3 +177,5 @@ describe('init', () => {
});
});
});

/* eslint-enable */

0 comments on commit 429877d

Please sign in to comment.