Skip to content
Permalink
Browse files
chore: precompile with babel (#257)
  • Loading branch information
SimenB committed May 12, 2019
1 parent 8670804 commit 48e3a59f5acd7939bf7145192deab66e6e589cff
Showing with 798 additions and 51 deletions.
  1. +1 −0 .eslintignore
  2. +3 −1 .eslintrc.js
  3. +1 −0 .gitignore
  4. +5 −0 babel.config.js
  5. +19 −6 package.json
  6. +4 −4 { → src}/__tests__/rules.test.js
  7. +1 −1 { → src}/index.js
  8. 0 { → src}/processors/__tests__/snapshot-processor.test.js
  9. +1 −1 { → src}/processors/snapshot-processor.js
  10. 0 { → src}/rules/__tests__/__snapshots__/no-large-snapshots.test.js.snap
  11. +1 −1 { → src}/rules/__tests__/consistent-test-it.test.js
  12. 0 { → src}/rules/__tests__/expect-expect.test.js
  13. 0 { → src}/rules/__tests__/lowercase-name.test.js
  14. 0 { → src}/rules/__tests__/no-alias-methods.test.js
  15. 0 { → src}/rules/__tests__/no-disabled-tests.test.js
  16. 0 { → src}/rules/__tests__/no-empty-title.js
  17. 0 { → src}/rules/__tests__/no-focused-tests.test.js
  18. 0 { → src}/rules/__tests__/no-hooks.test.js
  19. +4 −4 { → src}/rules/__tests__/no-identical-title.test.js
  20. 0 { → src}/rules/__tests__/no-jasmine-globals.test.js
  21. 0 { → src}/rules/__tests__/no-jest-import.test.js
  22. +4 −4 { → src}/rules/__tests__/no-large-snapshots.test.js
  23. 0 { → src}/rules/__tests__/no-mocks-import.test.js
  24. 0 { → src}/rules/__tests__/no-test-callback.test.js
  25. 0 { → src}/rules/__tests__/no-test-prefixes.test.js
  26. 0 { → src}/rules/__tests__/no-test-return-statement.test.js
  27. 0 { → src}/rules/__tests__/no-truthy-falsy.test.js
  28. 0 { → src}/rules/__tests__/prefer-called-with.js
  29. 0 { → src}/rules/__tests__/prefer-expect-assertions.test.js
  30. 0 { → src}/rules/__tests__/prefer-inline-snapshots.test.js
  31. 0 { → src}/rules/__tests__/prefer-spy-on.test.js
  32. 0 { → src}/rules/__tests__/prefer-strict-equal.test.js
  33. 0 { → src}/rules/__tests__/prefer-to-be-null.test.js
  34. 0 { → src}/rules/__tests__/prefer-to-be-undefined.test.js
  35. 0 { → src}/rules/__tests__/prefer-to-contain.test.js
  36. 0 { → src}/rules/__tests__/prefer-to-have-length.test.js
  37. 0 { → src}/rules/__tests__/prefer-todo.test.js
  38. 0 { → src}/rules/__tests__/require-tothrow-message.test.js
  39. 0 { → src}/rules/__tests__/valid-describe.test.js
  40. 0 { → src}/rules/__tests__/valid-expect-in-promise.test.js
  41. 0 { → src}/rules/__tests__/valid-expect.test.js
  42. +2 −2 { → src}/rules/consistent-test-it.js
  43. +2 −2 { → src}/rules/expect-expect.js
  44. 0 { → src}/rules/lowercase-name.js
  45. +1 −1 { → src}/rules/no-alias-methods.js
  46. 0 { → src}/rules/no-disabled-tests.js
  47. 0 { → src}/rules/no-empty-title.js
  48. 0 { → src}/rules/no-focused-tests.js
  49. 0 { → src}/rules/no-hooks.js
  50. +1 −1 { → src}/rules/no-identical-title.js
  51. +1 −1 { → src}/rules/no-jasmine-globals.js
  52. 0 { → src}/rules/no-jest-import.js
  53. 0 { → src}/rules/no-large-snapshots.js
  54. 0 { → src}/rules/no-mocks-import.js
  55. 0 { → src}/rules/no-test-callback.js
  56. 0 { → src}/rules/no-test-prefixes.js
  57. 0 { → src}/rules/no-test-return-statement.js
  58. 0 { → src}/rules/no-truthy-falsy.js
  59. 0 { → src}/rules/prefer-called-with.js
  60. 0 { → src}/rules/prefer-expect-assertions.js
  61. +2 −2 { → src}/rules/prefer-inline-snapshots.js
  62. +2 −2 { → src}/rules/prefer-spy-on.js
  63. 0 { → src}/rules/prefer-strict-equal.js
  64. 0 { → src}/rules/prefer-to-be-null.js
  65. 0 { → src}/rules/prefer-to-be-undefined.js
  66. +4 −4 { → src}/rules/prefer-to-contain.js
  67. +1 −1 { → src}/rules/prefer-to-have-length.js
  68. 0 { → src}/rules/prefer-todo.js
  69. 0 { → src}/rules/require-tothrow-message.js
  70. +1 −1 { → src}/rules/util.js
  71. 0 { → src}/rules/valid-describe.js
  72. +2 −2 { → src}/rules/valid-expect-in-promise.js
  73. 0 { → src}/rules/valid-expect.js
  74. +735 −10 yarn.lock
@@ -1 +1,2 @@
coverage/
lib/
@@ -1,6 +1,6 @@
'use strict';

const { globals } = require('./index').environments.globals;
const { globals } = require('./').environments.globals;

module.exports = {
extends: [
@@ -32,6 +32,8 @@ module.exports = {
},
],
'prettier/prettier': 'error',
'node/no-unsupported-features/es-syntax': 'off',
'node/no-unsupported-features/es-builtins': 'error',
},
overrides: [
{
@@ -1,2 +1,3 @@
node_modules/
coverage/
lib/
@@ -0,0 +1,5 @@
'use strict';

module.exports = {
presets: [['@babel/preset-env', { targets: { node: 6 } }]],
};
@@ -16,24 +16,31 @@
},
"files": [
"docs/",
"rules/",
"processors/",
"index.js"
"src/",
"lib/"
],
"main": "lib/",
"engines": {
"node": ">=6"
},
"peerDependencies": {
"eslint": ">=5"
},
"scripts": {
"postinstall": "yarn build",
"lint": "eslint . --ignore-pattern '!.eslintrc.js'",
"prettylint": "prettylint docs/**/*.md README.md package.json",
"test": "jest"
"prepublishOnly": "yarn build",
"test": "jest",
"build": "babel src --out-dir lib"
},
"devDependencies": {
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.4",
"@babel/preset-env": "^7.4.4",
"@commitlint/cli": "^7.0.0",
"@commitlint/config-conventional": "^7.0.1",
"babel-jest": "^24.8.0",
"eslint": "^5.1.0",
"eslint-config-prettier": "^4.1.0",
"eslint-plugin-eslint-plugin": "^2.0.0",
@@ -49,7 +56,7 @@
"prettier": {
"proseWrap": "always",
"singleQuote": true,
"trailingComma": "es5"
"trailingComma": "all"
},
"lint-staged": {
"*.js": [
@@ -73,13 +80,19 @@
"projects": [
{
"displayName": "test",
"testEnvironment": "node"
"testEnvironment": "node",
"testPathIgnorePatterns": [
"<rootDir>/lib/.*"
]
},
{
"displayName": "lint",
"runner": "jest-runner-eslint",
"testMatch": [
"<rootDir>/**/*.js"
],
"testPathIgnorePatterns": [
"<rootDir>/lib/.*"
]
}
]
@@ -2,19 +2,19 @@

const fs = require('fs');
const path = require('path');
const { rules } = require('../index');
const { rules } = require('../');

const ruleNames = Object.keys(rules);
const numberOfRules = 31;

describe('rules', () => {
it('should have a corresponding doc for each rule', () => {
ruleNames.forEach(rule => {
const docPath = path.resolve(__dirname, '../docs/rules', `${rule}.md`);
const docPath = path.resolve(__dirname, '../../docs/rules', `${rule}.md`);

if (!fs.existsSync(docPath)) {
throw new Error(
`Could not find documentation file for rule "${rule}" in path "${docPath}"`
`Could not find documentation file for rule "${rule}" in path "${docPath}"`,
);
}
});
@@ -24,7 +24,7 @@ describe('rules', () => {
const { length } = ruleNames;
if (length !== numberOfRules) {
throw new Error(
`There should be exactly ${numberOfRules} rules, but there are ${length}. If you've added a new rule, please update this number.`
`There should be exactly ${numberOfRules} rules, but there are ${length}. If you've added a new rule, please update this number.`,
);
}
});
@@ -9,7 +9,7 @@ const rules = fs
.map(rule => path.basename(rule, '.js'))
.reduce(
(acc, curr) => Object.assign(acc, { [curr]: require(`./rules/${curr}`) }),
{}
{},
);

const snapshotProcessor = require('./processors/snapshot-processor');
@@ -6,7 +6,7 @@ const preprocess = source => [source];
const postprocess = messages =>
messages[0].filter(
// snapshot files should only be linted with snapshot specific rules
message => message.ruleId === 'jest/no-large-snapshots'
message => message.ruleId === 'jest/no-large-snapshots',
);

module.exports = {
@@ -285,7 +285,7 @@ ruleTester.run(
output: 'test("foo")',
},
],
}
},
);

ruleTester.run('consistent-test-it with fn=it and withinDescribe=it ', rule, {
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -23,10 +23,10 @@ ruleTester.run('no-identical-title', rule, {
['it("it1", function() {});', 'it("it2", function() {});'].join('\n'),
['it.only("it1", function() {});', 'it("it2", function() {});'].join('\n'),
['it.only("it1", function() {});', 'it.only("it2", function() {});'].join(
'\n'
'\n',
),
['describe("title", function() {});', 'it("title", function() {});'].join(
'\n'
'\n',
),
[
'describe("describe1", function() {',
@@ -136,7 +136,7 @@ ruleTester.run('no-identical-title', rule, {
},
{
code: ['it("it1", function() {});', 'it("it1", function() {});'].join(
'\n'
'\n',
),
errors: [
{
@@ -163,7 +163,7 @@ ruleTester.run('no-identical-title', rule, {
},
{
code: ['fit("it1", function() {});', 'it("it1", function() {});'].join(
'\n'
'\n',
),
errors: [
{
File renamed without changes.
File renamed without changes.
@@ -15,21 +15,21 @@ ruleTester.run('no-large-snapshots', rule, {
{
filename: 'mock.js',
code: `expect(something).toMatchInlineSnapshot(\`\n${'line\n'.repeat(
2
2,
)}\`);`,
},
{
filename: 'mock.js',
code: `expect(something).toThrowErrorMatchingInlineSnapshot(\`\n${'line\n'.repeat(
2
2,
)}\`);`,
},
],
invalid: [
{
filename: 'mock.js',
code: `expect(something).toMatchInlineSnapshot(\`\n${'line\n'.repeat(
50
50,
)}\`);`,
errors: [
{
@@ -41,7 +41,7 @@ ruleTester.run('no-large-snapshots', rule, {
{
filename: 'mock.js',
code: `expect(something).toThrowErrorMatchingInlineSnapshot(\`\n${'line\n'.repeat(
50
50,
)}\`);`,
errors: [
{
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -69,7 +69,7 @@ module.exports = {
nodeName.indexOf(testKeywordWithinDescribe) === -1
) {
const oppositeTestKeyword = getOppositeTestKeyword(
testKeywordWithinDescribe
testKeywordWithinDescribe,
);

context.report({
@@ -85,7 +85,7 @@ module.exports = {

const fixedNodeName = getPreferredNodeName(
nodeName,
testKeywordWithinDescribe
testKeywordWithinDescribe,
);
return [fixer.replaceText(nodeToReplace, fixedNodeName)];
},
@@ -30,7 +30,7 @@ module.exports = {
const assertFunctionNames = new Set(
context.options[0] && context.options[0].assertFunctionNames
? context.options[0].assertFunctionNames
: ['expect']
: ['expect'],
);

return {
@@ -54,7 +54,7 @@ module.exports = {
context.report({
message: 'Test has no assertions',
node,
})
}),
);
},
};
File renamed without changes.
@@ -47,7 +47,7 @@ module.exports = {

// Check if the method used matches any of ours
const methodItem = methodNames.find(
item => item[1] === targetNode.name
item => item[1] === targetNode.name,
);

if (methodItem) {
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -75,7 +75,7 @@ module.exports = {
context,
currentLayer.describeTitles,
node,
title
title,
);
},
'CallExpression:exit'(node) {
@@ -127,7 +127,7 @@ module.exports = {
return [
fixer.replaceText(
node.parent,
`jest.setTimeout(${node.parent.right.value})`
`jest.setTimeout(${node.parent.right.value})`,
),
];
},
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -19,7 +19,7 @@ module.exports = {
return [
fixer.replaceText(
node.callee.property,
'toMatchInlineSnapshot'
'toMatchInlineSnapshot',
),
];
},
@@ -32,7 +32,7 @@ module.exports = {
return [
fixer.replaceText(
node.callee.property,
'toThrowErrorMatchingInlineSnapshot'
'toThrowErrorMatchingInlineSnapshot',
),
];
},
@@ -54,11 +54,11 @@ module.exports = {
fixer.insertTextBefore(node.left, `jest.spyOn(`),
fixer.replaceTextRange(
[node.left.object.range[1], node.left.property.range[0]],
`, ${leftPropQuote}`
`, ${leftPropQuote}`,
),
fixer.replaceTextRange(
[node.left.property.range[1], jestFnCall.range[1]],
`${leftPropQuote})${mockImplementation}`
`${leftPropQuote})${mockImplementation}`,
),
];
},
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -39,7 +39,7 @@ const getNegationFixes = (node, sourceCode, fixer) => {
const negationPropertyDot = sourceCode.getFirstTokenBetween(
node.parent.object,
node.parent.property,
token => token.value === '.'
token => token.value === '.',
);
const toContainFunc =
isEqualityNegation(node) && argument(node.parent).value
@@ -63,7 +63,7 @@ const getCommonFixes = (node, sourceCode, fixer) => {
const propertyDot = sourceCode.getFirstTokenBetween(
includesCaller.object,
includesCaller.property,
token => token.value === '.'
token => token.value === '.',
);

const closingParenthesis = sourceCode.getTokenAfter(containArg);
@@ -114,8 +114,8 @@ module.exports = {
fixArr.push(
fixer.replaceText(
argument(node),
sourceCode.getText(containArg)
)
sourceCode.getText(containArg),
),
);
return fixArr;
},
@@ -35,7 +35,7 @@ module.exports = {
.getFirstTokenBetween(
node.arguments[0].object,
node.arguments[0].property,
token => token.value === '.'
token => token.value === '.',
);
context.report({
fix(fixer) {
File renamed without changes.
File renamed without changes.
@@ -1,7 +1,7 @@
'use strict';

const path = require('path');
const { version } = require('../package.json');
const { version } = require('../../package.json');

const REPO_URL = 'https://github.com/jest-community/eslint-plugin-jest';

File renamed without changes.
@@ -98,7 +98,7 @@ const verifyExpectWithReturn = (
promiseCallbacks,
node,
context,
testFunctionBody
testFunctionBody,
) => {
promiseCallbacks.some(promiseCallback => {
if (promiseCallback && isFunction(promiseCallback)) {
@@ -156,7 +156,7 @@ module.exports = {
[fulfillmentCallback, rejectionCallback],
node,
context,
testFunctionBody
testFunctionBody,
);
}
}
File renamed without changes.

0 comments on commit 48e3a59

Please sign in to comment.