Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eslint-plugin-jest-formatting

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-jest-formatting - npm Package Compare versions

Comparing version 3.0.0 to 3.1.0

.github/workflows/codeql-analysis.yml

23

lib/ast-utils.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPaddingLineSequences = exports.getActualLastToken = exports.isValidParent = exports.areTokensOnSameLine = exports.isTokenASemicolon = void 0;
exports.isTokenASemicolon = (token) => token.value === ';' && token.type === 'Punctuator';
exports.areTokensOnSameLine = (left, right) => left.loc.end.line === right.loc.start.line;
const isTokenASemicolon = (token) => token.value === ';' && token.type === 'Punctuator';
exports.isTokenASemicolon = isTokenASemicolon;
const areTokensOnSameLine = (left, right) => left.loc.end.line === right.loc.start.line;
exports.areTokensOnSameLine = areTokensOnSameLine;
const STATEMENT_LIST_PARENTS = new Set([

@@ -12,6 +14,7 @@ 'Program',

]);
exports.isValidParent = (parentType) => {
const isValidParent = (parentType) => {
return STATEMENT_LIST_PARENTS.has(parentType);
};
exports.getActualLastToken = (sourceCode, node) => {
exports.isValidParent = isValidParent;
const getActualLastToken = (sourceCode, node) => {
const semiToken = sourceCode.getLastToken(node);

@@ -23,3 +26,3 @@ const prevToken = sourceCode.getTokenBefore(semiToken);

prevToken.range[0] >= node.range[0] &&
exports.isTokenASemicolon(semiToken) &&
(0, exports.isTokenASemicolon)(semiToken) &&
semiToken.loc.start.line !== prevToken.loc.end.line &&

@@ -29,9 +32,12 @@ semiToken.loc.end.line === nextToken.loc.start.line);

};
exports.getPaddingLineSequences = (prevNode, nextNode, sourceCode) => {
exports.getActualLastToken = getActualLastToken;
const getPaddingLineSequences = (prevNode, nextNode, sourceCode) => {
const pairs = [];
const includeComments = true;
let prevToken = exports.getActualLastToken(sourceCode, prevNode);
let prevToken = (0, exports.getActualLastToken)(sourceCode, prevNode);
if (nextNode.loc.start.line - prevToken.loc.end.line >= 2) {
do {
const token = sourceCode.getTokenAfter(prevToken, { includeComments });
const token = sourceCode.getTokenAfter(prevToken, {
includeComments,
});
if (token.loc.start.line - prevToken.loc.end.line >= 2) {

@@ -45,1 +51,2 @@ pairs.push([prevToken, token]);

};
exports.getPaddingLineSequences = getPaddingLineSequences;

@@ -117,10 +117,10 @@ "use strict";

exports.rules = {
'padding-around-after-all-blocks': padding_1.createRule(paddingConfigs.afterAll),
'padding-around-after-each-blocks': padding_1.createRule(paddingConfigs.afterEach),
'padding-around-before-all-blocks': padding_1.createRule(paddingConfigs.beforeAll),
'padding-around-before-each-blocks': padding_1.createRule(paddingConfigs.beforeEach),
'padding-around-describe-blocks': padding_1.createRule(paddingConfigs.describe),
'padding-around-expect-groups': padding_1.createRule(paddingConfigs.expect),
'padding-around-test-blocks': padding_1.createRule(paddingConfigs.test),
'padding-around-all': padding_1.createRule([].concat(...Object.keys(paddingConfigs).map((k) => paddingConfigs[k]))),
'padding-around-after-all-blocks': (0, padding_1.createRule)(paddingConfigs.afterAll),
'padding-around-after-each-blocks': (0, padding_1.createRule)(paddingConfigs.afterEach),
'padding-around-before-all-blocks': (0, padding_1.createRule)(paddingConfigs.beforeAll),
'padding-around-before-each-blocks': (0, padding_1.createRule)(paddingConfigs.beforeEach),
'padding-around-describe-blocks': (0, padding_1.createRule)(paddingConfigs.describe),
'padding-around-expect-groups': (0, padding_1.createRule)(paddingConfigs.expect),
'padding-around-test-blocks': (0, padding_1.createRule)(paddingConfigs.test),
'padding-around-all': (0, padding_1.createRule)([].concat(...Object.keys(paddingConfigs).map((k) => paddingConfigs[k]))),
};

@@ -127,0 +127,0 @@ exports.configs = {

@@ -67,3 +67,3 @@ "use strict";

let prevToken = astUtils.getActualLastToken(sourceCode, prevNode);
const nextToken = sourceCode.getFirstTokenBetween(prevToken, nextNode, {
const nextToken = (sourceCode.getFirstTokenBetween(prevToken, nextNode, {
includeComments: true,

@@ -77,3 +77,3 @@ filter(token) {

},
}) || nextNode;
}) || nextNode);
const insertText = astUtils.areTokensOnSameLine(prevToken, nextToken)

@@ -142,3 +142,3 @@ ? '\n\n'

};
exports.createRule = (configs, deprecated = false) => ({
const createRule = (configs, deprecated = false) => ({
meta: {

@@ -172,1 +172,2 @@ fixable: 'whitespace',

});
exports.createRule = createRule;
{
"name": "eslint-plugin-jest-formatting",
"version": "3.0.0",
"version": "3.1.0",
"description": "ESLint rules for formatting jest tests",

@@ -33,24 +33,24 @@ "keywords": [

"devDependencies": {
"@types/eslint": "^7.2.0",
"@types/jest": "^26.0.0",
"@types/node": "^14.0.13",
"@typescript-eslint/eslint-plugin": "^3.4.0",
"@typescript-eslint/parser": "^3.4.0",
"eslint": "^7.3.1",
"eslint-config-airbnb-base": "^14.2.0",
"eslint-config-prettier": "^6.11.0",
"eslint-import-resolver-typescript": "^2.0.0",
"eslint-plugin-import": "^2.21.2",
"eslint-plugin-jest": "^23.17.1",
"@types/eslint": "^7.29.0",
"@types/jest": "^27.0.2",
"@types/node": "^16.11.7",
"@typescript-eslint/eslint-plugin": "^5.4.0",
"@typescript-eslint/parser": "^5.4.0",
"eslint": "^8.2.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.3.0",
"eslint-import-resolver-typescript": "^2.5.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-jest": "^25.2.4",
"eslint-plugin-jest-formatting": "file:.",
"eslint-plugin-prettier": "^3.1.4",
"jest": "^26.1.0",
"prettier": "2.0.5",
"typescript": "^3.9.5",
"ts-jest": "^26.1.1"
"eslint-plugin-prettier": "^4.0.0",
"jest": "^27.3.1",
"prettier": "2.4.1",
"typescript": "^4.4.4",
"ts-jest": "^27.0.7"
},
"engines": {
"node": "^10.12.0 || >=12.0.0"
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
},
"license": "MIT"
}

@@ -69,3 +69,5 @@ import { AST, SourceCode } from 'eslint';

do {
const token = sourceCode.getTokenAfter(prevToken, { includeComments });
const token = sourceCode.getTokenAfter(prevToken, {
includeComments,
}) as AST.Token;

@@ -72,0 +74,0 @@ if (token.loc.start.line - prevToken.loc.end.line >= 2) {

@@ -45,8 +45,2 @@ /**

type PaddingTester = (
prevNode: Node,
nextNode: Node,
paddingContext: PaddingContext,
) => void;
// A configuration object for padding type and the two statement types

@@ -59,10 +53,2 @@ export interface Config {

// Tracks position in scope and prevNode. Used to compare current and prev node
// and then to walk back up to the parent scope or down into the next one.
// And so on...
interface Scope {
upper: Scope | null;
prevNode: Node | null;
}
interface ScopeInfo {

@@ -81,2 +67,16 @@ prevNode: Node | null;

type PaddingTester = (
prevNode: Node,
nextNode: Node,
paddingContext: PaddingContext,
) => void;
// Tracks position in scope and prevNode. Used to compare current and prev node
// and then to walk back up to the parent scope or down into the next one.
// And so on...
interface Scope {
upper: Scope | null;
prevNode: Node | null;
}
// Creates a StatementTester to test an ExpressionStatement's first token name

@@ -149,31 +149,30 @@ const createTokenTester = (tokenName: string): StatementTester => {

let prevToken = astUtils.getActualLastToken(sourceCode, prevNode);
const nextToken =
sourceCode.getFirstTokenBetween(prevToken, nextNode, {
includeComments: true,
/**
* Skip the trailing comments of the previous node.
* This inserts a blank line after the last trailing comment.
*
* For example:
*
* foo(); // trailing comment.
* // comment.
* bar();
*
* Get fixed to:
*
* foo(); // trailing comment.
*
* // comment.
* bar();
*/
filter(token: AST.Token): boolean {
if (astUtils.areTokensOnSameLine(prevToken, token)) {
prevToken = token;
return false;
}
const nextToken = (sourceCode.getFirstTokenBetween(prevToken, nextNode, {
includeComments: true,
/**
* Skip the trailing comments of the previous node.
* This inserts a blank line after the last trailing comment.
*
* For example:
*
* foo(); // trailing comment.
* // comment.
* bar();
*
* Get fixed to:
*
* foo(); // trailing comment.
*
* // comment.
* bar();
*/
filter(token: AST.Token): boolean {
if (astUtils.areTokensOnSameLine(prevToken, token)) {
prevToken = token;
return false;
}
return true;
},
}) || nextNode;
return true;
},
}) || nextNode) as AST.Token;

@@ -180,0 +179,0 @@ const insertText = astUtils.areTokensOnSameLine(prevToken, nextToken)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc