Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jest-community/eslint-plugin-jest
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v24.0.1
Choose a base ref
...
head repository: jest-community/eslint-plugin-jest
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v24.0.2
Choose a head ref
  • 6 commits
  • 6 files changed
  • 3 contributors

Commits on Sep 13, 2020

  1. Copy the full SHA
    a3ede08 View commit details

Commits on Sep 14, 2020

  1. Copy the full SHA
    57ef99f View commit details

Commits on Sep 19, 2020

  1. Copy the full SHA
    8810d67 View commit details

Commits on Sep 20, 2020

  1. Copy the full SHA
    b4319e8 View commit details
  2. Copy the full SHA
    d462d50 View commit details
  3. chore(release): 24.0.2 [skip ci]

    ## [24.0.2](v24.0.1...v24.0.2) (2020-09-20)
    
    ### Bug Fixes
    
    * **no-if:** check both types of function expression ([#672](#672)) ([d462d50](d462d50)), closes [#670](#670)
    semantic-release-bot committed Sep 20, 2020
    Copy the full SHA
    c8a040a View commit details
Showing with 728 additions and 647 deletions.
  1. +7 −0 CHANGELOG.md
  2. +3 −3 package.json
  3. +335 −279 src/rules/__tests__/no-if.test.ts
  4. +59 −58 src/rules/__tests__/valid-describe.test.ts
  5. +6 −4 src/rules/no-if.ts
  6. +318 −303 yarn.lock
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [24.0.2](https://github.com/jest-community/eslint-plugin-jest/compare/v24.0.1...v24.0.2) (2020-09-20)


### Bug Fixes

* **no-if:** check both types of function expression ([#672](https://github.com/jest-community/eslint-plugin-jest/issues/672)) ([d462d50](https://github.com/jest-community/eslint-plugin-jest/commit/d462d50aed84ad4dc536a1f47bb7af6abd3dbe92)), closes [#670](https://github.com/jest-community/eslint-plugin-jest/issues/670)

## [24.0.1](https://github.com/jest-community/eslint-plugin-jest/compare/v24.0.0...v24.0.1) (2020-09-12)


6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-jest",
"version": "24.0.1",
"version": "24.0.2",
"description": "Eslint rules for Jest",
"keywords": [
"eslint",
@@ -88,8 +88,8 @@
"@babel/core": "^7.4.4",
"@babel/preset-env": "^7.4.4",
"@babel/preset-typescript": "^7.3.3",
"@commitlint/cli": "^9.1.1",
"@commitlint/config-conventional": "^9.1.1",
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"@schemastore/package": "^0.0.6",
"@semantic-release/changelog": "^5.0.1",
"@semantic-release/git": "^9.0.0",
614 changes: 335 additions & 279 deletions src/rules/__tests__/no-if.test.ts

Large diffs are not rendered by default.

117 changes: 59 additions & 58 deletions src/rules/__tests__/valid-describe.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { TSESLint } from '@typescript-eslint/experimental-utils';
import dedent from 'dedent';
import resolveFrom from 'resolve-from';
import rule from '../valid-describe';

@@ -24,30 +25,30 @@ ruleTester.run('valid-describe', rule, {
'fdescribe("foo", () => {})',
'describe.only("foo", () => {})',
'describe.skip("foo", () => {})',
`
describe('foo', () => {
it('bar', () => {
return Promise.resolve(42).then(value => {
expect(value).toBe(42)
dedent`
describe('foo', () => {
it('bar', () => {
return Promise.resolve(42).then(value => {
expect(value).toBe(42)
})
})
})
})
`,
`
describe('foo', () => {
it('bar', async () => {
expect(await Promise.resolve(42)).toBe(42)
dedent`
describe('foo', () => {
it('bar', async () => {
expect(await Promise.resolve(42)).toBe(42)
})
})
})
`,
`
describe('foo', () =>
test('bar', () => {})
)
dedent`
describe('foo', () =>
test('bar', () => {})
)
`,
`
if (hasOwnProperty(obj, key)) {
}
dedent`
if (hasOwnProperty(obj, key)) {
}
`,
],
invalid: [
@@ -114,72 +115,72 @@ ruleTester.run('valid-describe', rule, {
errors: [{ messageId: 'noAsyncDescribeCallback', line: 1, column: 22 }],
},
{
code: `
describe('sample case', () => {
it('works', () => {
expect(true).toEqual(true);
});
describe('async', async () => {
await new Promise(setImmediate);
it('breaks', () => {
throw new Error('Fail');
code: dedent`
describe('sample case', () => {
it('works', () => {
expect(true).toEqual(true);
});
describe('async', async () => {
await new Promise(setImmediate);
it('breaks', () => {
throw new Error('Fail');
});
});
});
});
`,
errors: [{ messageId: 'noAsyncDescribeCallback', line: 6, column: 27 }],
errors: [{ messageId: 'noAsyncDescribeCallback', line: 5, column: 21 }],
},
{
code: `
describe('foo', function () {
return Promise.resolve().then(() => {
it('breaks', () => {
throw new Error('Fail')
code: dedent`
describe('foo', function () {
return Promise.resolve().then(() => {
it('breaks', () => {
throw new Error('Fail')
})
})
})
})
`,
errors: [{ messageId: 'unexpectedReturnInDescribe', line: 3, column: 9 }],
errors: [{ messageId: 'unexpectedReturnInDescribe', line: 2, column: 3 }],
},
{
code: `
describe('foo', () => {
return Promise.resolve().then(() => {
it('breaks', () => {
throw new Error('Fail')
})
})
describe('nested', () => {
code: dedent`
describe('foo', () => {
return Promise.resolve().then(() => {
it('breaks', () => {
throw new Error('Fail')
})
})
describe('nested', () => {
return Promise.resolve().then(() => {
it('breaks', () => {
throw new Error('Fail')
})
})
})
})
})
`,
errors: [
{ messageId: 'unexpectedReturnInDescribe', line: 3, column: 9 },
{ messageId: 'unexpectedReturnInDescribe', line: 9, column: 11 },
{ messageId: 'unexpectedReturnInDescribe', line: 2, column: 3 },
{ messageId: 'unexpectedReturnInDescribe', line: 8, column: 5 },
],
},
{
code: `
describe('foo', async () => {
await something()
it('does something')
describe('nested', () => {
return Promise.resolve().then(() => {
it('breaks', () => {
throw new Error('Fail')
code: dedent`
describe('foo', async () => {
await something()
it('does something')
describe('nested', () => {
return Promise.resolve().then(() => {
it('breaks', () => {
throw new Error('Fail')
})
})
})
})
})
`,
errors: [
{ messageId: 'noAsyncDescribeCallback', line: 2, column: 23 },
{ messageId: 'unexpectedReturnInDescribe', line: 6, column: 11 },
{ messageId: 'noAsyncDescribeCallback', line: 1, column: 17 },
{ messageId: 'unexpectedReturnInDescribe', line: 5, column: 5 },
],
},
{
10 changes: 6 additions & 4 deletions src/rules/no-if.ts
Original file line number Diff line number Diff line change
@@ -23,7 +23,9 @@ const testCaseNames = new Set<string | null>([
'fit.concurrent',
]);

const isTestArrowFunction = (node: TSESTree.ArrowFunctionExpression) =>
const isTestFunctionExpression = (
node: TSESTree.ArrowFunctionExpression | TSESTree.FunctionExpression,
) =>
node.parent !== undefined &&
node.parent.type === AST_NODE_TYPES.CallExpression &&
testCaseNames.has(getNodeName(node.parent.callee));
@@ -77,8 +79,8 @@ export default createRule({
stack.push(true);
}
},
FunctionExpression() {
stack.push(false);
FunctionExpression(node) {
stack.push(isTestFunctionExpression(node));
},
FunctionDeclaration(node) {
const declaredVariables = context.getDeclaredVariables(node);
@@ -89,7 +91,7 @@ export default createRule({
stack.push(testCallExpressions.length > 0);
},
ArrowFunctionExpression(node) {
stack.push(isTestArrowFunction(node));
stack.push(isTestFunctionExpression(node));
},
IfStatement: validate,
SwitchStatement: validate,
621 changes: 318 additions & 303 deletions yarn.lock

Large diffs are not rendered by default.