diff --git a/dist/index.js b/dist/index.js index f0b0c09..72271a7 100644 --- a/dist/index.js +++ b/dist/index.js @@ -12,6 +12,7 @@ const _gqlRules = require("./gqlRules"); const _noRenamedTranslationImport = require("./noRenamedTranslationImport"); const _noUnawaitedSkeletons = require("./noUnawaitedSkeletons"); const _oneTranslationImport = require("./oneTranslationImport"); +const _noJestInProduction = require("./noJestInProduction"); const rules = { "one-translation-import-per-file": _oneTranslationImport.oneTranslationImport, "no-renamed-translation-import": _noRenamedTranslationImport.noRenamedTranslationImport, @@ -19,5 +20,6 @@ const rules = { "gql-operation-name": _gqlRules.gqlOperationName, "cross-reference": _crossReference.crossReference, "circular-dependency": _circularDependency.circularDependency, - "no-unawaited-skeletons": _noUnawaitedSkeletons.noUnawaitedSkeletons + "no-unawaited-skeletons": _noUnawaitedSkeletons.noUnawaitedSkeletons, + "no-jest-in-production": _noJestInProduction.noJestInProduction }; diff --git a/dist/noJestInProduction/index.js b/dist/noJestInProduction/index.js new file mode 100644 index 0000000..25237e5 --- /dev/null +++ b/dist/noJestInProduction/index.js @@ -0,0 +1,48 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +Object.defineProperty(exports, "noJestInProduction", { + enumerable: true, + get: ()=>_noJestInProduction +}); +const _noJestInProduction = /*#__PURE__*/ _interopRequireWildcard(require("./noJestInProduction")); +function _getRequireWildcardCache(nodeInterop) { + if (typeof WeakMap !== "function") return null; + var cacheBabelInterop = new WeakMap(); + var cacheNodeInterop = new WeakMap(); + return (_getRequireWildcardCache = function(nodeInterop) { + return nodeInterop ? cacheNodeInterop : cacheBabelInterop; + })(nodeInterop); +} +function _interopRequireWildcard(obj, nodeInterop) { + if (!nodeInterop && obj && obj.__esModule) { + return obj; + } + if (obj === null || typeof obj !== "object" && typeof obj !== "function") { + return { + default: obj + }; + } + var cache = _getRequireWildcardCache(nodeInterop); + if (cache && cache.has(obj)) { + return cache.get(obj); + } + var newObj = {}; + var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; + for(var key in obj){ + if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { + var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; + if (desc && (desc.get || desc.set)) { + Object.defineProperty(newObj, key, desc); + } else { + newObj[key] = obj[key]; + } + } + } + newObj.default = obj; + if (cache) { + cache.set(obj, newObj); + } + return newObj; +} diff --git a/dist/noJestInProduction/noJestInProduction.js b/dist/noJestInProduction/noJestInProduction.js new file mode 100644 index 0000000..f6d03ea --- /dev/null +++ b/dist/noJestInProduction/noJestInProduction.js @@ -0,0 +1,47 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); +} +_export(exports, { + meta: ()=>meta, + create: ()=>create +}); +const meta = { + type: "problem", + docs: { + description: "Prevents jest from being used in production code", + category: "no-jest-in-production", + recommended: false + }, + fixable: null, + schema: [] +}; +const create = (context)=>{ + // split the filepath into an array + const filePath = context.getFilename().split("/"); + // the last entry will always be the file name + const fileName = filePath.at(-1); + // Spec files are allowed to have jest, so we skip them + const isNotSpec = ()=>{ + return fileName && !fileName.includes(".spec."); + }; + const isNotValid = (node)=>{ + return isNotSpec() && node.name === "jest"; + }; + return { + Identifier (node) { + if (isNotValid(node)) { + context.report({ + node, + message: "Jest should not be used in production code" + }); + } + } + }; +}; diff --git a/package.json b/package.json index 73ebcc4..baceb06 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "Hossam Mourad", "Ryan O'Connor ", "Aidan Feuerherm ", - "Valentyn Patsera " + "Valentyn Patsera ", + "Omar Nasr " ], "license": "MIT", "private": false, diff --git a/src/index.js b/src/index.js index ada0522..aff77d7 100644 --- a/src/index.js +++ b/src/index.js @@ -4,6 +4,7 @@ import { gqlObjects, gqlOperationName } from "./gqlRules"; import { noRenamedTranslationImport } from "./noRenamedTranslationImport"; import { noUnawaitedSkeletons } from "./noUnawaitedSkeletons"; import { oneTranslationImport } from "./oneTranslationImport"; +import { noJestInProduction } from "./noJestInProduction"; const rules = { "one-translation-import-per-file": oneTranslationImport, @@ -13,6 +14,7 @@ const rules = { "cross-reference": crossReference, "circular-dependency": circularDependency, "no-unawaited-skeletons": noUnawaitedSkeletons, + "no-jest-in-production": noJestInProduction, }; export { rules }; diff --git a/src/noJestInProduction/index.js b/src/noJestInProduction/index.js new file mode 100644 index 0000000..70b172f --- /dev/null +++ b/src/noJestInProduction/index.js @@ -0,0 +1 @@ +export * as noJestInProduction from "./noJestInProduction"; diff --git a/src/noJestInProduction/noJestInProduction.js b/src/noJestInProduction/noJestInProduction.js new file mode 100644 index 0000000..93e3bef --- /dev/null +++ b/src/noJestInProduction/noJestInProduction.js @@ -0,0 +1,39 @@ +const meta = { + type: "problem", + docs: { + description: "Prevents jest from being used in production code", + category: "no-jest-in-production", + recommended: false, + }, + fixable: null, + schema: [], +}; + +const create = context => { + // split the filepath into an array + const filePath = context.getFilename().split("/"); + // the last entry will always be the file name + const fileName = filePath.at(-1); + + // Spec files are allowed to have jest, so we skip them + const isNotSpec = () => { + return fileName && !fileName.includes(".spec."); + }; + + const isNotValid = node => { + return isNotSpec() && node.name === "jest"; + }; + + return { + Identifier(node) { + if (isNotValid(node)) { + context.report({ + node, + message: "Jest should not be used in production code", + }); + } + }, + }; +}; + +export { meta, create };