@mehshekari/eslint-plugin-gsap-motion 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/NOTICE.md +83 -0
- package/README.md +101 -0
- package/index.mjs +156 -0
- package/lib/ast.mjs +527 -0
- package/lib/audit.mjs +91 -0
- package/lib/rules.mjs +1196 -0
- package/lib/source.mjs +212 -0
- package/lib/vendor/parser.mjs +15 -0
- package/package.json +58 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 mehran.shekari
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/NOTICE.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Notice
|
|
2
|
+
|
|
3
|
+
This skill — its instructions, references, presets, examples, templates and
|
|
4
|
+
scripts — is released under the MIT License. See [LICENSE](LICENSE).
|
|
5
|
+
|
|
6
|
+
## Third-party code in the audit
|
|
7
|
+
|
|
8
|
+
`scripts/lib/vendor/parser.mjs` bundles two MIT-licensed packages, so the audit
|
|
9
|
+
can read JavaScript and TypeScript without installing anything. It is generated
|
|
10
|
+
from the versions its first lines name.
|
|
11
|
+
|
|
12
|
+
### acorn
|
|
13
|
+
|
|
14
|
+
```text
|
|
15
|
+
MIT License
|
|
16
|
+
|
|
17
|
+
Copyright (C) 2012-2022 by various contributors (see AUTHORS)
|
|
18
|
+
|
|
19
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
20
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
21
|
+
in the Software without restriction, including without limitation the rights
|
|
22
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
23
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
24
|
+
furnished to do so, subject to the following conditions:
|
|
25
|
+
|
|
26
|
+
The above copyright notice and this permission notice shall be included in
|
|
27
|
+
all copies or substantial portions of the Software.
|
|
28
|
+
|
|
29
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
30
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
31
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
32
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
33
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
34
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
35
|
+
THE SOFTWARE.
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### @sveltejs/acorn-typescript
|
|
39
|
+
|
|
40
|
+
```text
|
|
41
|
+
MIT License
|
|
42
|
+
|
|
43
|
+
Copyright (c) 2022 Tyreal Hu
|
|
44
|
+
Copyright (c) 2025 The Svelte Team
|
|
45
|
+
|
|
46
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
47
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
48
|
+
in the Software without restriction, including without limitation the rights
|
|
49
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
50
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
51
|
+
furnished to do so, subject to the following conditions:
|
|
52
|
+
|
|
53
|
+
The above copyright notice and this permission notice shall be included in all
|
|
54
|
+
copies or substantial portions of the Software.
|
|
55
|
+
|
|
56
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
57
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
58
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
59
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
60
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
61
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
62
|
+
SOFTWARE.
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## GSAP is licensed separately
|
|
66
|
+
|
|
67
|
+
**GSAP is not part of this skill, and it is not MIT-licensed.** The code this
|
|
68
|
+
skill writes uses GSAP (`gsap`, its plugins, and `@gsap/react`), which is
|
|
69
|
+
published by GreenSock, now part of Webflow, under the GSAP Standard License:
|
|
70
|
+
<https://gsap.com/standard-license>
|
|
71
|
+
|
|
72
|
+
In short, at the time of writing: GSAP and every one of its plugins are free to
|
|
73
|
+
use, including in commercial projects. The notable restriction is that GSAP may
|
|
74
|
+
not be used, without Webflow's written consent, in a tool that lets people build
|
|
75
|
+
visual animations without code in competition with Webflow.
|
|
76
|
+
|
|
77
|
+
That summary is not legal advice. Read the licence itself before relying on it,
|
|
78
|
+
and check it again when you upgrade.
|
|
79
|
+
|
|
80
|
+
This skill does not bundle or redistribute GSAP. Install it from npm.
|
|
81
|
+
|
|
82
|
+
"GSAP" and "GreenSock" are trademarks of their respective owners. This project
|
|
83
|
+
is not affiliated with or endorsed by GreenSock or Webflow.
|
package/README.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# @mehshekari/eslint-plugin-gsap-motion
|
|
2
|
+
|
|
3
|
+
The [gsap-motion](https://github.com/mehShekari/gsap-motion) audit as ESLint
|
|
4
|
+
rules. It reports the GSAP failures that raise no error — a tween that outlives
|
|
5
|
+
its component, a tween allocated per pointer event, a plugin imported and never
|
|
6
|
+
registered — in your editor and in any lint run.
|
|
7
|
+
|
|
8
|
+
It runs the audit's own rules on the audit's own parse of each file. So it
|
|
9
|
+
reports exactly what `npx @mehshekari/gsap-motion audit` reports, on the same
|
|
10
|
+
lines, and the audit's
|
|
11
|
+
[measured precision](https://github.com/mehShekari/gsap-motion#measured-precision)
|
|
12
|
+
holds here too.
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install --save-dev --save-exact @mehshekari/eslint-plugin-gsap-motion
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
It needs ESLint 9 or 10 with flat config, and Node.js 18.18 or later. Pin the
|
|
21
|
+
exact version: a release can add a rule, or catch a case a rule used to miss,
|
|
22
|
+
and fail a build that passed.
|
|
23
|
+
|
|
24
|
+
## Configure
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
// eslint.config.mjs
|
|
28
|
+
import gsapMotion from "@mehshekari/eslint-plugin-gsap-motion";
|
|
29
|
+
|
|
30
|
+
export default [
|
|
31
|
+
// …your own config, with a parser for each kind of file you lint
|
|
32
|
+
{
|
|
33
|
+
files: ["**/*.{js,jsx,mjs,ts,tsx}"],
|
|
34
|
+
...gsapMotion.configs.recommended,
|
|
35
|
+
},
|
|
36
|
+
];
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`recommended` turns on every rule at the audit's level. It sets no `files` and
|
|
40
|
+
no parser. ESLint must already be able to read the file: `typescript-eslint` for
|
|
41
|
+
TypeScript, and JSX enabled for `.jsx`. The plugin never reads the tree that
|
|
42
|
+
parser builds.
|
|
43
|
+
|
|
44
|
+
### Plugins registered in another file
|
|
45
|
+
|
|
46
|
+
`gsap.registerPlugin` is global, and most apps call it once, in an entry file.
|
|
47
|
+
The command line collects registrations across every file it reads. ESLint reads
|
|
48
|
+
one file at a time, so name them:
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
{
|
|
52
|
+
rules: {
|
|
53
|
+
"gsap-motion/unregistered-plugin": ["error", { registered: ["ScrollTrigger", "SplitText"] }],
|
|
54
|
+
},
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Waiving a finding
|
|
59
|
+
|
|
60
|
+
The same waiver as the audit's: the rule's id plus `-ok`, with a reason, on the
|
|
61
|
+
flagged line or in the eight lines above it.
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
/* shared-plugin-id-ok — mounted exactly once, by the root layout. */
|
|
65
|
+
gsap.to("#dot", { motionPath: { path: "#track" } });
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
An `eslint-disable` comment silences ESLint only. The audit does not read those,
|
|
69
|
+
so a finding waived that way still fails `gsap-motion audit`.
|
|
70
|
+
|
|
71
|
+
## Rules
|
|
72
|
+
|
|
73
|
+
| Rule | Level | Catches |
|
|
74
|
+
| --- | --- | --- |
|
|
75
|
+
| `orphan-tween` | error | A tween created outside `useGSAP`, `gsap.context` or `contextSafe` in React — never reverted, and doubled by StrictMode |
|
|
76
|
+
| `unmanaged-instance` | error | `matchMedia`, `Observer`, `Draggable`, `ScrollSmoother` or `SplitText` created outside a context and never torn down |
|
|
77
|
+
| `tween-per-event` | error | A new tween allocated on every pointer, scroll or wheel event |
|
|
78
|
+
| `state-per-event` | error | React state set in a high-frequency handler — a re-render per frame |
|
|
79
|
+
| `shared-plugin-id` | error | A hardcoded `#id` in MotionPath or MorphSVG config, which two instances of a component will share |
|
|
80
|
+
| `unregistered-plugin` | error | A plugin imported and never registered, whose properties are silently ignored |
|
|
81
|
+
| `never-completes` | error | An `onComplete` that can never run: on a timeline holding a `repeat: -1` child, or on a tween or timeline that repeats forever |
|
|
82
|
+
| `dev-tool-shipped` | error | `GSDevTools` or `MotionPathHelper` imported statically, or unconditional `markers: true` |
|
|
83
|
+
| `dangling-listener` | warn | An event listener that is never removed, including inline handlers that cannot be |
|
|
84
|
+
| `layout-property` | warn | Animating `width`, `height`, `top`, `left`, margins or padding, which forces layout every frame |
|
|
85
|
+
| `trigger-per-item` | warn | A ScrollTrigger created per item in a loop |
|
|
86
|
+
| `eased-loop` | warn | An infinite repeat with an ease, which makes its own seam visible |
|
|
87
|
+
| `eased-scrub` | warn | Easing inside a scrubbed ScrollTrigger, which fights the scrollbar |
|
|
88
|
+
| `late-transform-origin` | warn | A `fromTo` whose origin is only in its to-vars while its from-vars scale, rotate or skew, which leaves an SVG element offset |
|
|
89
|
+
| `missing-reduced-motion` | warn | An animating file with no `prefers-reduced-motion` branch |
|
|
90
|
+
| `barrel-import` | warn | Importing from `gsap/all`, which pulls in every plugin |
|
|
91
|
+
| `not-parsed` | warn | A file that uses GSAP and that the audit's parser could not read, so no other rule checked it |
|
|
92
|
+
|
|
93
|
+
`not-parsed` is an info finding in the command line; ESLint has no info level.
|
|
94
|
+
|
|
95
|
+
The plugin checks the files the command line checks: `.js`, `.jsx`, `.mjs`,
|
|
96
|
+
`.ts` and `.tsx`. A file that never mentions GSAP is not parsed at all.
|
|
97
|
+
|
|
98
|
+
## License
|
|
99
|
+
|
|
100
|
+
MIT. The bundled parser — acorn, with @sveltejs/acorn-typescript — is MIT too;
|
|
101
|
+
see `NOTICE.md`.
|
package/index.mjs
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The gsap-motion audit, as ESLint rules.
|
|
3
|
+
*
|
|
4
|
+
* Every rule here is the audit's own rule, run on the audit's own parse of the
|
|
5
|
+
* file — not on the tree the project's ESLint parser built. So the editor and
|
|
6
|
+
* `gsap-motion audit` report the same findings on the same lines, the precision
|
|
7
|
+
* measured for the command line holds here too, and a waiver means the same in
|
|
8
|
+
* both. The project's parser only has to accept the file; nothing reads its
|
|
9
|
+
* tree.
|
|
10
|
+
*
|
|
11
|
+
* `lib/` is the audit's own `scripts/lib`, copied in by scripts/bundle-audit.mjs
|
|
12
|
+
* before the package is packed or tested.
|
|
13
|
+
*/
|
|
14
|
+
import { readFileSync } from "node:fs";
|
|
15
|
+
import { extname } from "node:path";
|
|
16
|
+
|
|
17
|
+
import { check, mentionsGsap, NOT_PARSED, notParsed } from "./lib/audit.mjs";
|
|
18
|
+
import { RULES } from "./lib/rules.mjs";
|
|
19
|
+
import { fromText, hasSourceExtension } from "./lib/source.mjs";
|
|
20
|
+
|
|
21
|
+
const pkg = JSON.parse(
|
|
22
|
+
readFileSync(new URL("./package.json", import.meta.url), "utf8"),
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
const NAMESPACE = "gsap-motion";
|
|
26
|
+
const DOCS = "https://github.com/mehShekari/gsap-motion#the-audit";
|
|
27
|
+
|
|
28
|
+
/** ESLint has no info level. The one info finding, `not-parsed`, warns. */
|
|
29
|
+
const severity = (level) => (level === "info" ? "warn" : level);
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Parsed once per file, however many of the rules run on it: ESLint hands every
|
|
33
|
+
* rule the same SourceCode for a file. `null` marks a file the audit does not
|
|
34
|
+
* read.
|
|
35
|
+
*/
|
|
36
|
+
const sources = new WeakMap();
|
|
37
|
+
|
|
38
|
+
function sourceFor(context) {
|
|
39
|
+
const { sourceCode, filename } = context;
|
|
40
|
+
if (!sources.has(sourceCode)) {
|
|
41
|
+
/**
|
|
42
|
+
* The files the command line reads and no others, so the two report the
|
|
43
|
+
* same findings. A name with no extension — code piped in as `<text>` — is
|
|
44
|
+
* read as JavaScript with JSX.
|
|
45
|
+
*/
|
|
46
|
+
const readable = !extname(filename) || hasSourceExtension(filename);
|
|
47
|
+
const source = readable ? fromText(sourceCode.text, filename) : null;
|
|
48
|
+
sources.set(sourceCode, source && mentionsGsap(source) ? source : null);
|
|
49
|
+
}
|
|
50
|
+
return sources.get(sourceCode);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const MESSAGES = { finding: "{{ message }} {{ hint }}" };
|
|
54
|
+
|
|
55
|
+
function report(context, finding) {
|
|
56
|
+
context.report({
|
|
57
|
+
loc: { line: finding.line, column: finding.column },
|
|
58
|
+
messageId: "finding",
|
|
59
|
+
data: { message: finding.message, hint: finding.hint },
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* ESLint lints one file at a time, so a plugin registered in another file —
|
|
65
|
+
* once, in the app's entry — cannot be seen from this one. The command line
|
|
66
|
+
* collects registrations across the files it audits; here the project names
|
|
67
|
+
* them.
|
|
68
|
+
*/
|
|
69
|
+
const REGISTERED = [
|
|
70
|
+
{
|
|
71
|
+
type: "object",
|
|
72
|
+
properties: {
|
|
73
|
+
registered: {
|
|
74
|
+
type: "array",
|
|
75
|
+
items: { type: "string" },
|
|
76
|
+
uniqueItems: true,
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
additionalProperties: false,
|
|
80
|
+
},
|
|
81
|
+
];
|
|
82
|
+
|
|
83
|
+
function toEslintRule(rule) {
|
|
84
|
+
return {
|
|
85
|
+
meta: {
|
|
86
|
+
type: "problem",
|
|
87
|
+
docs: { description: rule.description, recommended: true, url: DOCS },
|
|
88
|
+
messages: MESSAGES,
|
|
89
|
+
schema: rule.id === "unregistered-plugin" ? REGISTERED : [],
|
|
90
|
+
},
|
|
91
|
+
create(context) {
|
|
92
|
+
const source = sourceFor(context);
|
|
93
|
+
if (!source || source.parseError) return {};
|
|
94
|
+
return {
|
|
95
|
+
Program() {
|
|
96
|
+
const file = Object.create(source, {
|
|
97
|
+
registeredElsewhere: {
|
|
98
|
+
value: new Set(context.options[0]?.registered),
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
for (const finding of check(rule, file)) report(context, finding);
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const notParsedRule = {
|
|
109
|
+
meta: {
|
|
110
|
+
type: "problem",
|
|
111
|
+
docs: {
|
|
112
|
+
description:
|
|
113
|
+
"A file that uses GSAP and that the audit's parser could not read, so no other rule checked it",
|
|
114
|
+
recommended: true,
|
|
115
|
+
url: DOCS,
|
|
116
|
+
},
|
|
117
|
+
messages: MESSAGES,
|
|
118
|
+
schema: [],
|
|
119
|
+
},
|
|
120
|
+
create(context) {
|
|
121
|
+
const source = sourceFor(context);
|
|
122
|
+
if (!source?.parseError) return {};
|
|
123
|
+
return {
|
|
124
|
+
Program() {
|
|
125
|
+
const finding = notParsed(source);
|
|
126
|
+
if (finding) report(context, finding);
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const plugin = {
|
|
133
|
+
meta: { name: pkg.name, version: pkg.version, namespace: NAMESPACE },
|
|
134
|
+
rules: Object.fromEntries([
|
|
135
|
+
...RULES.map((rule) => [rule.id, toEslintRule(rule)]),
|
|
136
|
+
[NOT_PARSED, notParsedRule],
|
|
137
|
+
]),
|
|
138
|
+
configs: {},
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Every rule at the level the command line gives it.
|
|
143
|
+
*
|
|
144
|
+
* No `files`: the config applies to whatever the project already lints, and
|
|
145
|
+
* never widens that to files the project's parser cannot read.
|
|
146
|
+
*/
|
|
147
|
+
plugin.configs.recommended = {
|
|
148
|
+
name: `${NAMESPACE}/recommended`,
|
|
149
|
+
plugins: { [NAMESPACE]: plugin },
|
|
150
|
+
rules: Object.fromEntries([
|
|
151
|
+
...RULES.map((rule) => [`${NAMESPACE}/${rule.id}`, severity(rule.level)]),
|
|
152
|
+
[`${NAMESPACE}/${NOT_PARSED}`, severity("info")],
|
|
153
|
+
]),
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
export default plugin;
|