eslint-plugin-jest-formatting
Advanced tools
Comparing version 0.0.9 to 0.0.10
--- | ||
name: Bug report | ||
about: Create a report to help us improve | ||
title: "[BUG]" | ||
title: '[BUG]' | ||
labels: bug | ||
assignees: dangreenisrael | ||
--- | ||
@@ -15,2 +14,3 @@ | ||
Steps to reproduce the behavior: | ||
1. Go to '...' | ||
@@ -28,5 +28,6 @@ 2. Click on '....' | ||
**Desktop (please complete the following information):** | ||
- OS: [e.g. Mac, Linux Desktop, Linux CI, Windows] | ||
- OS: [e.g. Mac, Linux Desktop, Linux CI, Windows] | ||
**Additional context** | ||
Add any other context about the problem here. |
--- | ||
name: Rule Request | ||
about: Request a new formatting rule | ||
title: "[Rule]" | ||
title: '[Rule]' | ||
labels: Rule Request | ||
assignees: dangreenisrael | ||
--- | ||
*Explanation of the rule* | ||
_Explanation of the rule_ | ||
*Valid code example* | ||
_Valid code example_ | ||
```JavaScript | ||
@@ -17,5 +17,6 @@ | ||
*Invalid code example* | ||
_Invalid code example_ | ||
```JavaScript | ||
``` |
@@ -10,10 +10,8 @@ # padding-describe-blocks | ||
```js | ||
describe('foo', () => { | ||
// stuff | ||
}) | ||
describe('bar', ()=>{ | ||
}); | ||
describe('bar', () => { | ||
// more stuff | ||
}) | ||
}); | ||
``` | ||
@@ -24,11 +22,9 @@ | ||
```js | ||
describe('foo', () => { | ||
// stuff | ||
}) | ||
}); | ||
describe('bar', ()=>{ | ||
describe('bar', () => { | ||
// more stuff | ||
}) | ||
``` | ||
}); | ||
``` |
@@ -10,22 +10,21 @@ # padding-test-blocks | ||
```js | ||
describe('foo',()=>{ | ||
test('foo', ()=>{}) | ||
test('bar', ()=>{}) | ||
}) | ||
describe('foo', () => { | ||
test('foo', () => {}); | ||
test('bar', () => {}); | ||
}); | ||
``` | ||
```js | ||
describe('foo',()=>{ | ||
it('foo', ()=>{}) | ||
it('bar', ()=>{}) | ||
}) | ||
describe('foo', () => { | ||
it('foo', () => {}); | ||
it('bar', () => {}); | ||
}); | ||
``` | ||
```js | ||
describe('foo',()=>{ | ||
it('foo', ()=>{}) | ||
describe('foo', () => { | ||
it('foo', () => {}); | ||
it('bar', ()=>{}) | ||
}) | ||
it('bar', () => {}); | ||
}); | ||
``` | ||
@@ -36,23 +35,23 @@ | ||
```js | ||
describe('foo',()=>{ | ||
test('foo', ()=>{}) | ||
describe('foo', () => { | ||
test('foo', () => {}); | ||
test('bar', ()=>{}) | ||
}) | ||
test('bar', () => {}); | ||
}); | ||
``` | ||
```js | ||
describe('foo',()=>{ | ||
it('foo', ()=>{}) | ||
describe('foo', () => { | ||
it('foo', () => {}); | ||
it('bar', ()=>{}) | ||
}) | ||
it('bar', () => {}); | ||
}); | ||
``` | ||
```js | ||
describe('foo',()=>{ | ||
it('foo', ()=>{}) | ||
describe('foo', () => { | ||
it('foo', () => {}); | ||
it('bar', ()=>{}) | ||
}) | ||
it('bar', () => {}); | ||
}); | ||
``` | ||
@@ -59,0 +58,0 @@ |
@@ -1,25 +0,8 @@ | ||
/** | ||
* @fileoverview This contains formatting rules for jest in jest | ||
* @author Dan | ||
*/ | ||
"use strict"; | ||
//------------------------------------------------------------------------------ | ||
// Requirements | ||
//------------------------------------------------------------------------------ | ||
const paddingBeforeDescribeBlocks = require('./rules/padding-before-describe-blocks') | ||
const paddingBeforeTestBlocks = require('./rules/padding-before-test-blocks') | ||
//------------------------------------------------------------------------------ | ||
// Plugin Definition | ||
//------------------------------------------------------------------------------ | ||
// import all rules in lib/rules | ||
module.exports.rules = { | ||
'padding-before-describe-blocks':paddingBeforeDescribeBlocks, | ||
'padding-before-test-blocks':paddingBeforeTestBlocks, | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const padding_before_describe_blocks_1 = require("./rules/padding-before-describe-blocks"); | ||
const padding_before_test_blocks_1 = require("./rules/padding-before-test-blocks"); | ||
exports.rules = { | ||
'padding-before-describe-blocks': padding_before_describe_blocks_1.default, | ||
'padding-before-test-blocks': padding_before_test_blocks_1.default, | ||
}; |
@@ -1,48 +0,33 @@ | ||
/** | ||
* @fileoverview Enforces single line padding around describe blocks | ||
* @author Dan Green-Leipciger | ||
*/ | ||
"use strict"; | ||
const { padBefore } = require("../utils"); | ||
//------------------------------------------------------------------------------ | ||
// Rule Definition | ||
//------------------------------------------------------------------------------ | ||
const beforeMessage = | ||
"You need a newline or comment before a describe block when it comes after another expression"; | ||
const isDescribe = node => | ||
node.expression && | ||
node.expression.callee && | ||
node.expression.callee.name === "describe"; | ||
module.exports = { | ||
meta: { | ||
docs: { | ||
description: "Enforces at least a line of padding before describe blocks", | ||
category: "Fill me in", | ||
recommended: false | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const utils_1 = require("../utils"); | ||
const beforeMessage = 'You need a newline or comment before a describe block when it comes after another expression'; | ||
const isDescribe = node => node.expression && | ||
node.expression.callee && | ||
node.expression.callee.name === 'describe'; | ||
exports.default = { | ||
meta: { | ||
docs: { | ||
description: 'Enforces at least a line of padding before describe blocks', | ||
category: 'Fill me in', | ||
recommended: false, | ||
}, | ||
fixable: 'whitespace', | ||
schema: [], | ||
}, | ||
fixable: "whitespace", // or "code" or "whitespace" | ||
schema: [ | ||
// fill in your schema | ||
] | ||
}, | ||
beforeMessage, | ||
create(context) { | ||
const filePath = context && context.getFilename(); | ||
const isTest = | ||
filePath.includes("test") || | ||
filePath.includes("spec") || | ||
filePath.includes("<input>"); | ||
return { | ||
ExpressionStatement(node) { | ||
if (!isTest || !isDescribe(node)) { | ||
return; | ||
} | ||
padBefore({ context, node, beforeMessage }); | ||
} | ||
}; | ||
} | ||
beforeMessage, | ||
create(context) { | ||
const filePath = context && context.getFilename(); | ||
const isTest = filePath.includes('test') || | ||
filePath.includes('spec') || | ||
filePath.includes('<input>'); | ||
return { | ||
ExpressionStatement(node) { | ||
if (!isTest || !isDescribe(node)) { | ||
return; | ||
} | ||
utils_1.padBefore({ context, node, beforeMessage }); | ||
}, | ||
}; | ||
}, | ||
}; |
@@ -1,49 +0,32 @@ | ||
/** | ||
* @fileoverview Enforces a single like of padding between test blocks with a describe | ||
* @author Dan | ||
*/ | ||
"use strict"; | ||
const { padBefore } = require("../utils"); | ||
//------------------------------------------------------------------------------ | ||
// Rule Definition | ||
//------------------------------------------------------------------------------ | ||
const beforeMessage = | ||
"You need a newline or comment before an `it` or `test` block when it comes after another expression"; | ||
const expressionName = node => | ||
node.expression && node.expression.callee && node.expression.callee.name; | ||
const isTestBlock = node => | ||
expressionName(node) === "test" || expressionName(node) === "it"; | ||
module.exports = { | ||
meta: { | ||
docs: { | ||
description: | ||
"Enforces at least a line of padding before test blocks within a describe", | ||
category: "Formatting", | ||
recommended: true | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const utils_1 = require("../utils"); | ||
const beforeMessage = 'You need a newline or comment before an `it` or `test` block when it comes after another expression'; | ||
const expressionName = node => node.expression && node.expression.callee && node.expression.callee.name; | ||
const isTestBlock = node => expressionName(node) === 'test' || expressionName(node) === 'it'; | ||
exports.default = { | ||
meta: { | ||
docs: { | ||
description: 'Enforces at least a line of padding before test blocks within a describe', | ||
category: 'Formatting', | ||
recommended: true, | ||
}, | ||
fixable: 'whitespace', | ||
schema: [], | ||
}, | ||
fixable: "whitespace", // or "code" or "whitespace" | ||
schema: [ | ||
// fill in your schema | ||
] | ||
}, | ||
beforeMessage, | ||
create(context) { | ||
const filePath = context && context.getFilename(); | ||
const isTestFile = | ||
filePath.includes("test") || | ||
filePath.includes("spec") || | ||
filePath.includes("<input>"); | ||
return { | ||
ExpressionStatement(node) { | ||
if (!isTestFile || !isTestBlock(node)) { | ||
return; | ||
} | ||
padBefore({ context, node, beforeMessage }); | ||
} | ||
}; | ||
} | ||
beforeMessage, | ||
create(context) { | ||
const filePath = context && context.getFilename(); | ||
const isTestFile = filePath.includes('test') || | ||
filePath.includes('spec') || | ||
filePath.includes('<input>'); | ||
return { | ||
ExpressionStatement(node) { | ||
if (!isTestFile || !isTestBlock(node)) { | ||
return; | ||
} | ||
utils_1.padBefore({ context, node, beforeMessage }); | ||
}, | ||
}; | ||
}, | ||
}; |
@@ -1,43 +0,30 @@ | ||
const setPaddingBetweenNodes = ({ | ||
context, | ||
problemNode, | ||
firstNode, | ||
message | ||
}) => { | ||
context.report({ | ||
node: problemNode, | ||
message, | ||
fix: function(fixer) { | ||
return fixer.insertTextAfter(firstNode, "\n"); | ||
} | ||
}); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const setPaddingBetweenNodes = ({ context, problemNode, firstNode, message, }) => { | ||
context.report({ | ||
node: problemNode, | ||
message, | ||
fix: function (fixer) { | ||
return fixer.insertTextAfter(firstNode, '\n'); | ||
}, | ||
}); | ||
}; | ||
const getLeftSibling = node => { | ||
const siblings = node.parent.body; | ||
const nodePosition = siblings.indexOf(node); | ||
return siblings[nodePosition - 1]; | ||
const siblings = node.parent.body; | ||
const nodePosition = siblings.indexOf(node); | ||
return siblings[nodePosition - 1]; | ||
}; | ||
const getStartLine = node => node && node.loc.start.line; | ||
const getEndLine = node => node && node.loc.end.line; | ||
const shouldFixGap = (bottomNode, topNode) => | ||
getStartLine(topNode) - getEndLine(bottomNode) < 2; | ||
const padBefore = ({ context, node, beforeMessage }) => { | ||
const leftSibling = getLeftSibling(node); | ||
if (leftSibling && shouldFixGap(leftSibling, node)) { | ||
setPaddingBetweenNodes({ | ||
context, | ||
problemNode: node, | ||
firstNode: leftSibling, | ||
message: beforeMessage | ||
}); | ||
} | ||
const shouldFixGap = (bottomNode, topNode) => getStartLine(topNode) - getEndLine(bottomNode) < 2; | ||
exports.padBefore = ({ context, node, beforeMessage }) => { | ||
const leftSibling = getLeftSibling(node); | ||
if (leftSibling && shouldFixGap(leftSibling, node)) { | ||
setPaddingBetweenNodes({ | ||
context, | ||
problemNode: node, | ||
firstNode: leftSibling, | ||
message: beforeMessage, | ||
}); | ||
} | ||
}; | ||
module.exports = { | ||
padBefore | ||
}; |
{ | ||
"name": "eslint-plugin-jest-formatting", | ||
"version": "0.0.9", | ||
"description": "Formatting rules for test written with jest", | ||
"version": "0.0.10", | ||
"description": "Formatting rules for jest tests", | ||
"keywords": [ | ||
@@ -18,13 +18,31 @@ "eslint", | ||
"main": "lib/index.js", | ||
"module": "src/index.ts", | ||
"scripts": { | ||
"test": "jest" | ||
"pretty": "yarn prettier '**/*.*'", | ||
"lint": "yarn pretty --check && yarn eslint .", | ||
"format": "yarn build && yarn pretty --write && yarn eslint --fix .", | ||
"build": "tsc", | ||
"test": "yarn build && jest" | ||
}, | ||
"devDependencies": { | ||
"@types/eslint": "4.16.6", | ||
"@types/jest": "24.0.11", | ||
"@types/node": "8.10.0", | ||
"@typescript-eslint/parser": "1.10.2", | ||
"eslint": "5.16.0", | ||
"jest": "24.7.1" | ||
"eslint-config-airbnb-base": "13.1.0", | ||
"eslint-config-prettier": "5.0.0", | ||
"eslint-plugin-import": "2.14.0", | ||
"eslint-plugin-jest": "22.7.0", | ||
"eslint-plugin-jest-formatting": "^0.0.9", | ||
"eslint-plugin-prettier": "3.1.0", | ||
"jest": "24.8.0", | ||
"prettier": "1.18.2", | ||
"typescript": "3.4.1", | ||
"ts-jest": "24.0.2" | ||
}, | ||
"engines": { | ||
"node": ">=8.0.0" | ||
"node": "8.10.0" | ||
}, | ||
"license": "MIT" | ||
} |
@@ -1,12 +0,10 @@ | ||
[![CircleCI](https://circleci.com/gh/dangreenisrael/eslint-plugin-jest-formatting/tree/master.svg?style=svg)](https://circleci.com/gh/dangreenisrael/eslint-plugin-jest-formatting/tree/master) [![star this repo](http://githubbadges.com/star.svg?user=dangreenisrael&repo=eslint-plugin-jest-formatting&style=flat)](https://github.com/dangreenisrael/eslint-plugin-jest-formatting/stargazers) | ||
[![CircleCI](https://circleci.com/gh/dangreenisrael/eslint-plugin-jest-formatting/tree/master.svg?style=svg)](https://circleci.com/gh/dangreenisrael/eslint-plugin-jest-formatting/tree/master) | ||
![npm monthly downloads](https://img.shields.io/npm/dm/eslint-plugin-jest-formatting.svg) | ||
# eslint-plugin-jest-formatting | ||
Formatting rules for tests written in jest | ||
This project aims to provide formatting rules (auto-fixable where possible) to ensure consistency and readability in jest test suites. | ||
Like this plugin? [Say thanks with a ⭐️](https://github.com/dangreenisrael/eslint-plugin-jest-formatting/stargazers) | ||
## Installation | ||
@@ -34,9 +32,6 @@ | ||
{ | ||
"plugins": [ | ||
"jest-formatting" | ||
] | ||
"plugins": ["jest-formatting"] | ||
} | ||
``` | ||
Then configure the rules you want to use under the rules section. | ||
@@ -46,6 +41,6 @@ | ||
{ | ||
"rules": { | ||
"jest-formatting/padding-before-test-blocks": 2, | ||
"jest-formatting/padding-before-describe-blocks": 2, | ||
} | ||
"rules": { | ||
"jest-formatting/padding-before-test-blocks": 2, | ||
"jest-formatting/padding-before-describe-blocks": 2 | ||
} | ||
} | ||
@@ -56,10 +51,4 @@ ``` | ||
* [padding-before-test-blocks](docs/rules/padding-before-test-blocks.md) | ||
- [padding-before-test-blocks](docs/rules/padding-before-test-blocks.md) | ||
* [padding-before-describe-blocks](docs/rules/padding-before-describe-blocks.md) | ||
<!-- Github button script --> | ||
<script async defer src="https://buttons.github.io/buttons.js"></script> | ||
- [padding-before-describe-blocks](docs/rules/padding-before-describe-blocks.md) |
{ | ||
"extends": [ | ||
"config:base" | ||
] | ||
"extends": ["config:base"] | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
190619
25
15
259
52
1