eslint-plugin-reanimated
Advanced tools
Comparing version 1.0.14 to 1.1.0
@@ -7,5 +7,7 @@ "use strict"; | ||
const js_function_in_worklet_1 = __importDefault(require("./js-function-in-worklet")); | ||
const unsupported_syntax_1 = __importDefault(require("./unsupported-syntax")); | ||
const rules = { | ||
"js-function-in-worklet": js_function_in_worklet_1.default, | ||
"unsupported-syntax": unsupported_syntax_1.default, | ||
}; | ||
exports.default = rules; |
@@ -5,21 +5,6 @@ "use strict"; | ||
const typescript_1 = require("typescript"); | ||
const common_1 = require("./common"); | ||
const createRule = experimental_utils_1.ESLintUtils.RuleCreator((name) => { | ||
return `https://github.com/wcandillon/eslint-plugin-reanimated/blob/master/docs/${name}.md`; | ||
}); | ||
const functionHooks = new Map([ | ||
["useAnimatedStyle", [0]], | ||
["useAnimatedProps", [0]], | ||
["useDerivedValue", [0]], | ||
["useAnimatedScrollHandler", [0]], | ||
["useAnimatedReaction", [0, 1]], | ||
["useWorkletCallback", [0]], | ||
["createWorklet", [0]], | ||
// animations' callbacks | ||
["withTiming", [2]], | ||
["withSpring", [2]], | ||
["withDecay", [1]], | ||
["withRepeat", [3]], | ||
]); | ||
const functionNames = Array.from(functionHooks.keys()); | ||
const matchFunctions = `/${functionNames.join("|")}/`; | ||
const JSFunctionInWorkletMessage = "{{name}} is not a worklet. Use runOnJS instead."; | ||
@@ -39,3 +24,2 @@ const isVarInScope = (name, scope) => { | ||
}; | ||
const WORKLET = "worklet"; | ||
const URI_PREFIX = "/node_modules/"; | ||
@@ -86,3 +70,3 @@ const getModuleURI = (n) => { | ||
const tags = typescript_1.getJSDocTags(parent); | ||
return (tags.filter((tag) => tag.tagName.getText() === WORKLET).length > 0); | ||
return (tags.filter((tag) => tag.tagName.getText() === common_1.WORKLET).length > 0); | ||
} | ||
@@ -99,3 +83,3 @@ else if (decl !== undefined && | ||
.getText() | ||
.substring(1, WORKLET.length + 1) === WORKLET); | ||
.substring(1, common_1.WORKLET.length + 1) === common_1.WORKLET); | ||
} | ||
@@ -106,39 +90,5 @@ } | ||
}; | ||
let currentCodePath = null; | ||
let callerIsWorklet = false; | ||
return { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
onCodePathStart: (...args) => { | ||
var _a; | ||
const [codePath, node] = args; | ||
if ((node.type === "ArrowFunctionExpression" || | ||
node.type === "FunctionDeclaration") && | ||
node.body.type === "BlockStatement" && | ||
node.body.body.length > 0 && | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
((_a = node.body.body[0]) === null || _a === void 0 ? void 0 : _a.directive) === WORKLET) { | ||
currentCodePath = codePath.id; | ||
callerIsWorklet = true; | ||
} | ||
}, | ||
onCodePathEnd: (codePath) => { | ||
if (codePath.id === currentCodePath) { | ||
currentCodePath = null; | ||
callerIsWorklet = false; | ||
} | ||
}, | ||
["CallExpression[callee.name='useAnimatedGestureHandler'] > ObjectExpression"]: () => { | ||
callerIsWorklet = true; | ||
}, | ||
["CallExpression[callee.name='useAnimatedGestureHandler'] > ObjectExpression:exit"]: () => { | ||
callerIsWorklet = false; | ||
}, | ||
[`CallExpression[callee.name=${matchFunctions}] > ArrowFunctionExpression`]: () => { | ||
callerIsWorklet = true; | ||
}, | ||
[`CallExpression[callee.name=${matchFunctions}] > ArrowFunctionExpression:exit`]: () => { | ||
callerIsWorklet = false; | ||
}, | ||
CallExpression: (node) => { | ||
if (callerIsWorklet) { | ||
const state = common_1.createState(); | ||
return Object.assign(Object.assign({}, common_1.detectWorklet(state)), { CallExpression: (node) => { | ||
if (state.callerIsWorklet) { | ||
const tsNode = parserServices.esTreeNodeToTSNodeMap.get(node); | ||
@@ -179,5 +129,4 @@ const { expression } = tsNode; | ||
} | ||
}, | ||
}; | ||
} }); | ||
}, | ||
}); |
{ | ||
"name": "eslint-plugin-reanimated", | ||
"version": "1.0.14", | ||
"version": "1.1.0", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -13,3 +13,4 @@ [![NPM](https://img.shields.io/npm/v/eslint-plugin-reanimated)](https://www.npmjs.com/package/eslint-plugin-reanimated) [![CI & CD](https://github.com/wcandillon/eslint-plugin-reanimated/workflows/CI%20&%20CD/badge.svg)](https://github.com/wcandillon/eslint-plugin-reanimated/actions?query=branch%3Amaster) | ||
External type declaration need to expose the `@worklet` JSDoc. In the case of `react-native-redash` for instance, this is done starting version `16.0.6`. | ||
External type declaration need to expose the `@worklet` JSDoc. | ||
In the case of `react-native-redash`, this is done starting version `16.0.6` ([see js-function-in-worklet](https://github.com/wcandillon/eslint-plugin-reanimated/blob/master/docs/js-function-in-worklet.md)). | ||
@@ -36,1 +37,2 @@ ## Example Configuration | ||
* [js-function-in-worklet](https://github.com/wcandillon/eslint-plugin-reanimated/blob/master/docs/js-function-in-worklet.md) | ||
* [unsupported-syntax](https://github.com/wcandillon/eslint-plugin-reanimated/blob/master/docs/unsupported-syntax) |
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
14479
7
295
37