Created
February 21, 2022 01:37
-
-
Save nossbigg/1ba5f6bfb2030eaeb3d38128099c84bf to your computer and use it in GitHub Desktop.
ESLint rule: @safetyculture/no-render-import-testing-library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @fileoverview tbc | |
* @author nossbigg | |
*/ | |
"use strict"; | |
//------------------------------------------------------------------------------ | |
// Rule Definition | |
//------------------------------------------------------------------------------ | |
module.exports = { | |
meta: { | |
type: "problem", // `problem`, `suggestion`, or `layout` | |
docs: { | |
description: | |
"Discourages usage of `render` in favor of `initRender()` from `@safetyculture/testing-library`", | |
category: "testing", | |
recommended: false, | |
url: null, // URL to the documentation page for this rule | |
}, | |
fixable: "code", // Or `code` or `whitespace` | |
schema: [], // Add a schema if the rule has options | |
}, | |
create(context) { | |
// variables should be defined here | |
//---------------------------------------------------------------------- | |
// Helpers | |
//---------------------------------------------------------------------- | |
// any helper functions should go here or else delete this section | |
//---------------------------------------------------------------------- | |
// Public | |
//---------------------------------------------------------------------- | |
return { | |
ImportDeclaration: (node) => { | |
if (node.source.value !== "@safetyculture/testing-library") { | |
return; | |
} | |
const firstRenderImport = node.specifiers.find( | |
(s) => s.imported.name === "render", | |
); | |
if (!firstRenderImport) { | |
return; | |
} | |
context.report({ | |
node: firstRenderImport, | |
message: "No 'render' import. Did you mean to use 'initRender'?", | |
fix: (fixer) => { | |
return fixer.replaceText(firstRenderImport, "initRender"); | |
}, | |
}); | |
}, | |
}; | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment