eslint-plugin-jest
Advanced tools
Comparing version 22.6.2 to 22.6.3
'use strict'; | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
const fs = require('fs'); | ||
const path = require('path'); // copied from https://github.com/babel/babel/blob/56044c7851d583d498f919e9546caddf8f80a72f/packages/babel-helpers/src/helpers.js#L558-L562 | ||
const path = require('path'); | ||
function interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : { | ||
default: obj | ||
}; | ||
} | ||
const rules = fs.readdirSync(path.join(__dirname, 'rules')).filter(rule => rule !== '__tests__' && rule !== 'util.js' && rule !== 'tsUtils.ts').map(rule => rule.endsWith('js') ? path.basename(rule, '.js') : path.basename(rule, '.ts')).reduce((acc, curr) => _objectSpread({}, acc, { | ||
[curr]: interopRequireDefault(require(`./rules/${curr}`)).default | ||
const rules = fs.readdirSync(path.join(__dirname, 'rules')).filter(rule => rule !== '__tests__' && rule !== 'util.js').map(rule => path.basename(rule, '.js')).reduce((acc, curr) => Object.assign(acc, { | ||
[curr]: require(`./rules/${curr}`) | ||
}), {}); | ||
@@ -21,0 +10,0 @@ |
@@ -1,12 +0,9 @@ | ||
"use strict"; | ||
'use strict'; | ||
var _eslint = require("eslint"); | ||
const _require = require('eslint'), | ||
RuleTester = _require.RuleTester; | ||
var _lowercaseName = _interopRequireDefault(require("../lowercase-name")); | ||
const rule = require('../lowercase-name'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
const RuleTester = _eslint.RuleTester; | ||
const ruleTester = new RuleTester({ | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
@@ -16,4 +13,4 @@ ecmaVersion: 6 | ||
}); | ||
ruleTester.run('lowercase-name', _lowercaseName.default, { | ||
valid: ['randomFunction()', 'foo.bar()', 'it()', "it(' ', function () {})", 'it(" ", function () {})', 'it(` `, function () {})', "it('foo', function () {})", 'it("foo", function () {})', 'it(`foo`, function () {})', 'it("<Foo/>", function () {})', 'it("123 foo", function () {})', 'it(42, function () {})', 'it(``)', 'it("")', 'it(42)', 'test()', "test('foo', function () {})", 'test("foo", function () {})', 'test(`foo`, function () {})', 'test("<Foo/>", function () {})', 'test("123 foo", function () {})', 'test("42", function () {})', 'test(``)', 'test("")', 'test(42)', 'describe()', "describe('foo', function () {})", 'describe("foo", function () {})', 'describe(`foo`, function () {})', 'describe("<Foo/>", function () {})', 'describe("123 foo", function () {})', 'describe("42", function () {})', 'describe(function () {})', 'describe(``)', 'describe("")', 'describe(42)'], | ||
ruleTester.run('lowercase-name', rule, { | ||
valid: ['it()', "it(' ', function () {})", 'it(" ", function () {})', 'it(` `, function () {})', "it('foo', function () {})", 'it("foo", function () {})', 'it(`foo`, function () {})', 'it("<Foo/>", function () {})', 'it("123 foo", function () {})', 'it(42, function () {})', 'it(``)', 'test()', "test('foo', function () {})", 'test("foo", function () {})', 'test(`foo`, function () {})', 'test("<Foo/>", function () {})', 'test("123 foo", function () {})', 'test("42", function () {})', 'test(``)', 'describe()', "describe('foo', function () {})", 'describe("foo", function () {})', 'describe(`foo`, function () {})', 'describe("<Foo/>", function () {})', 'describe("123 foo", function () {})', 'describe("42", function () {})', 'describe(function () {})', 'describe(``)'], | ||
invalid: [{ | ||
@@ -23,6 +20,3 @@ code: "it('Foo', function () {})", | ||
errors: [{ | ||
messageId: 'unexpectedLowercase', | ||
data: { | ||
method: 'it' | ||
}, | ||
message: '`it`s should begin with lowercase', | ||
column: 1, | ||
@@ -35,6 +29,3 @@ line: 1 | ||
errors: [{ | ||
messageId: 'unexpectedLowercase', | ||
data: { | ||
method: 'it' | ||
}, | ||
message: '`it`s should begin with lowercase', | ||
column: 1, | ||
@@ -47,6 +38,3 @@ line: 1 | ||
errors: [{ | ||
messageId: 'unexpectedLowercase', | ||
data: { | ||
method: 'it' | ||
}, | ||
message: '`it`s should begin with lowercase', | ||
column: 1, | ||
@@ -59,6 +47,3 @@ line: 1 | ||
errors: [{ | ||
messageId: 'unexpectedLowercase', | ||
data: { | ||
method: 'test' | ||
}, | ||
message: '`test`s should begin with lowercase', | ||
column: 1, | ||
@@ -71,6 +56,3 @@ line: 1 | ||
errors: [{ | ||
messageId: 'unexpectedLowercase', | ||
data: { | ||
method: 'test' | ||
}, | ||
message: '`test`s should begin with lowercase', | ||
column: 1, | ||
@@ -83,6 +65,3 @@ line: 1 | ||
errors: [{ | ||
messageId: 'unexpectedLowercase', | ||
data: { | ||
method: 'test' | ||
}, | ||
message: '`test`s should begin with lowercase', | ||
column: 1, | ||
@@ -95,6 +74,3 @@ line: 1 | ||
errors: [{ | ||
messageId: 'unexpectedLowercase', | ||
data: { | ||
method: 'describe' | ||
}, | ||
message: '`describe`s should begin with lowercase', | ||
column: 1, | ||
@@ -107,6 +83,3 @@ line: 1 | ||
errors: [{ | ||
messageId: 'unexpectedLowercase', | ||
data: { | ||
method: 'describe' | ||
}, | ||
message: '`describe`s should begin with lowercase', | ||
column: 1, | ||
@@ -119,6 +92,3 @@ line: 1 | ||
errors: [{ | ||
messageId: 'unexpectedLowercase', | ||
data: { | ||
method: 'describe' | ||
}, | ||
message: '`describe`s should begin with lowercase', | ||
column: 1, | ||
@@ -131,6 +101,3 @@ line: 1 | ||
errors: [{ | ||
messageId: 'unexpectedLowercase', | ||
data: { | ||
method: 'describe' | ||
}, | ||
message: '`describe`s should begin with lowercase', | ||
column: 1, | ||
@@ -141,3 +108,3 @@ line: 1 | ||
}); | ||
ruleTester.run('lowercase-name with ignore=describe', _lowercaseName.default, { | ||
ruleTester.run('lowercase-name with ignore=describe', rule, { | ||
valid: [{ | ||
@@ -161,3 +128,3 @@ code: "describe('Foo', function () {})", | ||
}); | ||
ruleTester.run('lowercase-name with ignore=test', _lowercaseName.default, { | ||
ruleTester.run('lowercase-name with ignore=test', rule, { | ||
valid: [{ | ||
@@ -181,3 +148,3 @@ code: "test('Foo', function () {})", | ||
}); | ||
ruleTester.run('lowercase-name with ignore=it', _lowercaseName.default, { | ||
ruleTester.run('lowercase-name with ignore=it', rule, { | ||
valid: [{ | ||
@@ -184,0 +151,0 @@ code: "it('Foo', function () {})", |
@@ -1,17 +0,11 @@ | ||
"use strict"; | ||
'use strict'; | ||
var _eslint = require("eslint"); | ||
const rule = require('../no-jest-import.js'); | ||
var _noJestImport = _interopRequireDefault(require("../no-jest-import")); | ||
const _require = require('eslint'), | ||
RuleTester = _require.RuleTester; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
const RuleTester = _eslint.RuleTester; | ||
const ruleTester = new RuleTester({ | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
ecmaVersion: 6 | ||
} | ||
}); | ||
ruleTester.run('no-jest-import', _noJestImport.default, { | ||
const ruleTester = new RuleTester(); | ||
const message = `Jest is automatically in scope. Do not import "jest", as Jest doesn't export anything.`; | ||
ruleTester.run('no-jest-import', rule, { | ||
valid: [{ | ||
@@ -28,3 +22,3 @@ code: 'import something from "something"', | ||
column: 9, | ||
messageId: 'unexpectedImport' | ||
message | ||
}] | ||
@@ -38,4 +32,4 @@ }, { | ||
endColumn: 24, | ||
column: 18, | ||
messageId: 'unexpectedImport' | ||
column: 1, | ||
message | ||
}] | ||
@@ -47,3 +41,3 @@ }, { | ||
column: 20, | ||
messageId: 'unexpectedImport' | ||
message | ||
}] | ||
@@ -57,4 +51,4 @@ }, { | ||
endColumn: 34, | ||
column: 28, | ||
messageId: 'unexpectedImport' | ||
column: 1, | ||
message | ||
}] | ||
@@ -69,5 +63,5 @@ }, { | ||
column: 22, | ||
messageId: 'unexpectedImport' | ||
message | ||
}] | ||
}] | ||
}); |
@@ -1,12 +0,3 @@ | ||
"use strict"; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _tsUtils = require("./tsUtils"); | ||
var _experimentalUtils = require("@typescript-eslint/experimental-utils"); | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); } | ||
@@ -20,84 +11,53 @@ | ||
const _require = require('./util'), | ||
getDocsUrl = _require.getDocsUrl; | ||
const isItTestOrDescribeFunction = node => { | ||
const callee = node.callee; | ||
return node.type === 'CallExpression' && node.callee && (node.callee.name === 'it' || node.callee.name === 'test' || node.callee.name === 'describe'); | ||
}; | ||
if (callee.type !== _experimentalUtils.AST_NODE_TYPES.Identifier) { | ||
return false; | ||
} | ||
const name = callee.name; | ||
return name === 'it' || name === 'test' || name === 'describe'; | ||
const isItDescription = node => { | ||
return node.arguments && node.arguments[0] && (node.arguments[0].type === 'Literal' || node.arguments[0].type === 'TemplateLiteral'); | ||
}; | ||
const hasStringAsFirstArgument = node => node.arguments && node.arguments[0] && (node.arguments[0].type === _experimentalUtils.AST_NODE_TYPES.Literal || node.arguments[0].type === _experimentalUtils.AST_NODE_TYPES.TemplateLiteral); | ||
const testDescription = node => { | ||
const _node$arguments = _slicedToArray(node.arguments, 1), | ||
firstArgument = _node$arguments[0]; | ||
const isJestFunctionWithLiteralArg = node => isItTestOrDescribeFunction(node) && hasStringAsFirstArgument(node); | ||
const type = firstArgument.type; | ||
const testDescription = argument => { | ||
if (argument.type === _experimentalUtils.AST_NODE_TYPES.Literal) { | ||
const value = argument.value; | ||
if (type === 'Literal') { | ||
return firstArgument.value; | ||
} // `isItDescription` guarantees this is `type === 'TemplateLiteral'` | ||
if (typeof value === 'string') { | ||
return value; | ||
} | ||
return null; | ||
} | ||
return argument.quasis[0].value.raw; | ||
return firstArgument.quasis[0].value.raw; | ||
}; | ||
const jestFunctionName = node => { | ||
const description = testDescription(node.arguments[0]); | ||
const descriptionBeginsWithLowerCase = node => { | ||
if (isItTestOrDescribeFunction(node) && isItDescription(node)) { | ||
const description = testDescription(node); | ||
if (description === null) { | ||
return null; | ||
} | ||
if (!description[0]) { | ||
return false; | ||
} | ||
const firstCharacter = description.charAt(0); | ||
if (!firstCharacter) { | ||
return null; | ||
if (description[0] !== description[0].toLowerCase()) { | ||
return node.callee.name; | ||
} | ||
} | ||
if (firstCharacter !== firstCharacter.toLowerCase()) { | ||
return node.callee.name; | ||
} | ||
return null; | ||
return false; | ||
}; | ||
var _default = (0, _tsUtils.createRule)({ | ||
name: __filename, | ||
module.exports = { | ||
meta: { | ||
type: 'suggestion', | ||
docs: { | ||
description: 'Enforce `it`, `test` and `describe` to have descriptions that begin with a lowercase letter. This provides more readable test failures.', | ||
category: 'Best Practices', | ||
recommended: false | ||
url: getDocsUrl(__filename) | ||
}, | ||
fixable: 'code', | ||
messages: { | ||
unexpectedLowercase: '`{{ method }}`s should begin with lowercase' | ||
}, | ||
schema: [{ | ||
type: 'object', | ||
additionalProperties: false, | ||
properties: { | ||
ignore: { | ||
type: 'array', | ||
items: { | ||
type: 'string' | ||
} | ||
} | ||
} | ||
}] | ||
fixable: 'code' | ||
}, | ||
defaultOptions: [{ | ||
ignore: [] | ||
}], | ||
create(context, [{ | ||
ignore | ||
}]) { | ||
create(context) { | ||
const ignore = context.options[0] && context.options[0].ignore || []; | ||
const ignoredFunctionNames = ignore.reduce((accumulator, value) => { | ||
@@ -112,11 +72,7 @@ accumulator[value] = true; | ||
CallExpression(node) { | ||
if (!isJestFunctionWithLiteralArg(node)) { | ||
return; | ||
} | ||
const erroneousMethod = descriptionBeginsWithLowerCase(node); | ||
const erroneousMethod = jestFunctionName(node); | ||
if (erroneousMethod && !isIgnoredFunctionName(node)) { | ||
context.report({ | ||
messageId: 'unexpectedLowercase', | ||
message: '`{{ method }}`s should begin with lowercase', | ||
data: { | ||
@@ -128,7 +84,6 @@ method: erroneousMethod | ||
fix(fixer) { | ||
const _node$arguments = _slicedToArray(node.arguments, 1), | ||
firstArg = _node$arguments[0]; // guaranteed by jestFunctionName | ||
const _node$arguments2 = _slicedToArray(node.arguments, 1), | ||
firstArg = _node$arguments2[0]; | ||
const description = testDescription(firstArg); | ||
const description = testDescription(node); | ||
const rangeIgnoringQuotes = [firstArg.range[0] + 1, firstArg.range[1] - 1]; | ||
@@ -146,4 +101,2 @@ const newDescription = description.substring(0, 1).toLowerCase() + description.substring(1); | ||
}); | ||
exports.default = _default; | ||
}; |
@@ -1,25 +0,13 @@ | ||
"use strict"; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
const _require = require('./util'), | ||
getDocsUrl = _require.getDocsUrl; | ||
var _tsUtils = require("./tsUtils"); | ||
var _default = (0, _tsUtils.createRule)({ | ||
name: __filename, | ||
const message = `Jest is automatically in scope. Do not import "jest", as Jest doesn't export anything.`; | ||
module.exports = { | ||
meta: { | ||
type: 'problem', | ||
docs: { | ||
description: "The `jest` object is automatically in scope within every test file. The methods in the `jest` object help create mocks and let you control Jest's overall behavior. It is therefore completely unnecessary to import in `jest`, as Jest doesn't export anything in the first place.", | ||
category: 'Best Practices', | ||
recommended: 'error' | ||
}, | ||
messages: { | ||
unexpectedImport: `Jest is automatically in scope. Do not import "jest", as Jest doesn't export anything.` | ||
}, | ||
schema: [] | ||
url: getDocsUrl(__filename) | ||
} | ||
}, | ||
defaultOptions: [], | ||
@@ -30,4 +18,4 @@ create(context) { | ||
context.report({ | ||
node: node.source, | ||
messageId: 'unexpectedImport' | ||
node, | ||
message | ||
}); | ||
@@ -38,4 +26,4 @@ }, | ||
context.report({ | ||
node: node.arguments[0], | ||
messageId: 'unexpectedImport' | ||
loc: node.arguments[0].loc, | ||
message | ||
}); | ||
@@ -47,4 +35,2 @@ } | ||
}); | ||
exports.default = _default; | ||
}; |
{ | ||
"name": "eslint-plugin-jest", | ||
"version": "22.6.2", | ||
"version": "22.6.3", | ||
"description": "Eslint rules for Jest", | ||
@@ -30,13 +30,9 @@ "repository": "jest-community/eslint-plugin-jest", | ||
"scripts": { | ||
"pretest": "yarn build", | ||
"lint": "eslint . --ignore-pattern '!.eslintrc.js' --ext js,ts", | ||
"prepare": "yarn build", | ||
"lint": "eslint . --ignore-pattern '!.eslintrc.js'", | ||
"prettylint": "prettylint docs/**/*.md README.md package.json", | ||
"prepublishOnly": "yarn build", | ||
"test": "jest", | ||
"build": "babel --extensions .js,.ts src --out-dir lib", | ||
"typecheck": "tsc -p ." | ||
"build": "babel src --out-dir lib" | ||
}, | ||
"dependencies": { | ||
"@typescript-eslint/experimental-utils": "^1.9.1-alpha.3" | ||
}, | ||
"devDependencies": { | ||
@@ -46,9 +42,4 @@ "@babel/cli": "^7.4.4", | ||
"@babel/preset-env": "^7.4.4", | ||
"@babel/preset-typescript": "^7.3.3", | ||
"@commitlint/cli": "^7.0.0", | ||
"@commitlint/config-conventional": "^7.0.1", | ||
"@types/eslint": "^4.16.6", | ||
"@types/jest": "^24.0.12", | ||
"@types/node": "^12.0.0", | ||
"@typescript-eslint/eslint-plugin": "^1.9.1-alpha.3", | ||
"babel-jest": "^24.8.0", | ||
@@ -65,4 +56,3 @@ "eslint": "^5.1.0", | ||
"prettier": "^1.10.2", | ||
"prettylint": "^1.0.0", | ||
"typescript": "^3.4.5" | ||
"prettylint": "^1.0.0" | ||
}, | ||
@@ -75,3 +65,3 @@ "prettier": { | ||
"lint-staged": { | ||
"*.{js,ts}": [ | ||
"*.js": [ | ||
"eslint --fix", | ||
@@ -78,0 +68,0 @@ "git add" |
@@ -6,22 +6,8 @@ 'use strict'; | ||
// copied from https://github.com/babel/babel/blob/56044c7851d583d498f919e9546caddf8f80a72f/packages/babel-helpers/src/helpers.js#L558-L562 | ||
function interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : { default: obj }; | ||
} | ||
const rules = fs | ||
.readdirSync(path.join(__dirname, 'rules')) | ||
.filter( | ||
rule => rule !== '__tests__' && rule !== 'util.js' && rule !== 'tsUtils.ts', | ||
) | ||
.map(rule => | ||
rule.endsWith('js') | ||
? path.basename(rule, '.js') | ||
: path.basename(rule, '.ts'), | ||
) | ||
.filter(rule => rule !== '__tests__' && rule !== 'util.js') | ||
.map(rule => path.basename(rule, '.js')) | ||
.reduce( | ||
(acc, curr) => ({ | ||
...acc, | ||
[curr]: interopRequireDefault(require(`./rules/${curr}`)).default, | ||
}), | ||
(acc, curr) => Object.assign(acc, { [curr]: require(`./rules/${curr}`) }), | ||
{}, | ||
@@ -28,0 +14,0 @@ ); |
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
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
1
17
384118
175
11670
- Removed@typescript-eslint/experimental-utils@^1.9.1-alpha.3
- Removed@typescript-eslint/experimental-utils@1.13.0(transitive)
- Removed@typescript-eslint/typescript-estree@1.13.0(transitive)
- Removedeslint-scope@4.0.3(transitive)
- Removedestraverse@4.3.0(transitive)
- Removedlodash.unescape@4.0.1(transitive)
- Removedsemver@5.5.0(transitive)