eslint-plugin-sfmc 4.8.3 → 4.9.0
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/README.md +48 -48
- package/package.json +3 -3
- package/src/ampscript-parser.js +1 -0
- package/src/rules/amp/prefer-attribute-value.js +51 -27
package/README.md
CHANGED
|
@@ -79,8 +79,8 @@ Use the `-next` config variants when targeting **Marketing Cloud Next (MCN)**. M
|
|
|
79
79
|
| ---------------------------------- | ------------------------------------ | ------------------------------------------------------------------------------------------- |
|
|
80
80
|
| `sfmc.configs['ampscript-next']` | `**/*.ampscript`, `**/*.amp` | AMPscript rules + flags functions unsupported in MCN (single config object) |
|
|
81
81
|
| `sfmc.configs['ssjs-next']` | `**/*.ssjs` | Flags all SSJS API calls as MCN-unsupported; all other SSJS quality rules disabled |
|
|
82
|
-
| `sfmc.configs['recommended-next']` | Both of the above + `**/*.hbs` | AMPscript MCN-aware + SSJS flagged + Handlebars rules for standalone `.hbs` files
|
|
83
|
-
| `sfmc.configs['embedded-next']` | `**/*.html`, `**/*.hbs` | AMPscript MCN-aware + SSJS flagged + Handlebars rules for HTML-embedded code and `.hbs`
|
|
82
|
+
| `sfmc.configs['recommended-next']` | Both of the above + `**/*.hbs` | AMPscript MCN-aware + SSJS flagged + Handlebars rules for standalone `.hbs` files |
|
|
83
|
+
| `sfmc.configs['embedded-next']` | `**/*.html`, `**/*.hbs` | AMPscript MCN-aware + SSJS flagged + Handlebars rules for HTML-embedded code and `.hbs` |
|
|
84
84
|
| `sfmc.configs['strict-next']` | All of the above + HTML + `**/*.hbs` | All AMPscript rules at `error` severity + MCN flag; SSJS fully flagged; Handlebars rules on |
|
|
85
85
|
|
|
86
86
|
Standalone `.hbs` files (VS Code's built-in **Handlebars** language) are treated as MCN by default — Handlebars only runs on Marketing Cloud Next, so a `.hbs` file is always linted with the full Handlebars rule set. This is deliberately wired **only** into the `-next` configs; the classic `recommended` / `strict` (Engagement) configs never lint `.hbs`.
|
|
@@ -122,30 +122,30 @@ export default [...sfmc.configs['recommended-next'], ...sfmc.configs['embedded-n
|
|
|
122
122
|
|
|
123
123
|
## SSJS Rules (`ssjs-*`)
|
|
124
124
|
|
|
125
|
-
| Rule | Default | Description
|
|
126
|
-
| ------------------------------------------------------------------------------------------- | ------------------------ |
|
|
127
|
-
| [`sfmc/ssjs-require-platform-load`](docs/rules/ssjs/require-platform-load.md) | `error` | Require `Platform.Load("core")` before Core or requiresCoreLoad globals
|
|
128
|
-
| [`sfmc/ssjs-no-unsupported-syntax`](docs/rules/ssjs/no-unsupported-syntax.md) | `error` | Flag ES6+ syntax not supported by SFMC
|
|
129
|
-
| [`sfmc/ssjs-no-unknown-function`](docs/rules/ssjs/no-unknown-function.md) | `error` | Disallow unknown methods on Platform.\*, HTTP, Core Library, and WSProxy
|
|
130
|
-
| [`sfmc/ssjs-no-mcn-unsupported`](docs/rules/ssjs/no-mcn-unsupported.md) | off (`error` in `-next`) | Flag all SSJS API usage as unsupported in Marketing Cloud Next
|
|
125
|
+
| Rule | Default | Description |
|
|
126
|
+
| ------------------------------------------------------------------------------------------- | ------------------------ | -------------------------------------------------------------------------- |
|
|
127
|
+
| [`sfmc/ssjs-require-platform-load`](docs/rules/ssjs/require-platform-load.md) | `error` | Require `Platform.Load("core")` before Core or requiresCoreLoad globals |
|
|
128
|
+
| [`sfmc/ssjs-no-unsupported-syntax`](docs/rules/ssjs/no-unsupported-syntax.md) | `error` | Flag ES6+ syntax not supported by SFMC |
|
|
129
|
+
| [`sfmc/ssjs-no-unknown-function`](docs/rules/ssjs/no-unknown-function.md) | `error` | Disallow unknown methods on Platform.\*, HTTP, Core Library, and WSProxy |
|
|
130
|
+
| [`sfmc/ssjs-no-mcn-unsupported`](docs/rules/ssjs/no-mcn-unsupported.md) | off (`error` in `-next`) | Flag all SSJS API usage as unsupported in Marketing Cloud Next |
|
|
131
131
|
| [`sfmc/ssjs-no-deprecated-function`](docs/rules/ssjs/no-deprecated-function.md) | `error` | Flag use of deprecated SFMC SSJS APIs (Classic Content classes, ErrorUtil) |
|
|
132
|
-
| [`sfmc/ssjs-no-nonexistent-global`](docs/rules/ssjs/no-nonexistent-global.md) | `error` | Flag documented SSJS globals that throw ReferenceError at runtime
|
|
133
|
-
| [`sfmc/ssjs-no-property-call`](docs/rules/ssjs/no-property-call.md) | `error` | Disallow calling Platform.Request/Response properties as functions
|
|
134
|
-
| [`sfmc/ssjs-no-clr-header-access`](docs/rules/ssjs/no-clr-header-access.md) | `error` | Disallow CLR-unsafe reads of `HttpResponse.headers`; read via `for..in`
|
|
135
|
-
| [`sfmc/ssjs-require-string-clr-content`](docs/rules/ssjs/require-string-clr-content.md) | `error` | Require wrapping `HttpResponse.content` with `String()` before use
|
|
136
|
-
| [`sfmc/ssjs-platform-function-arity`](docs/rules/ssjs/platform-function-arity.md) | `error` | Enforce correct arity for `Platform.Function.*`
|
|
137
|
-
| [`sfmc/ssjs-require-platform-load-order`](docs/rules/ssjs/require-platform-load-order.md) | `error` | Require `Platform.Load()` before Core usage in order
|
|
138
|
-
| [`sfmc/ssjs-no-hardcoded-credentials`](docs/rules/ssjs/no-hardcoded-credentials.md) | `error` | Flag hardcoded keys in encryption calls
|
|
139
|
-
| [`sfmc/ssjs-cache-loop-length`](docs/rules/ssjs/cache-loop-length.md) | `warn` | Require caching `.length` in for-loops
|
|
140
|
-
| [`sfmc/ssjs-require-hasownproperty`](docs/rules/ssjs/require-hasownproperty.md) | `warn` | Require `hasOwnProperty` guard in for-in loops
|
|
141
|
-
| [`sfmc/ssjs-prefer-platform-load-version`](docs/rules/ssjs/prefer-platform-load-version.md) | `warn` | Enforce a minimum `Platform.Load` version string
|
|
142
|
-
| [`sfmc/ssjs-no-unavailable-method`](docs/rules/ssjs/no-unavailable-method.md) | `warn` | Flag Array/String methods unavailable or broken in SFMC's ES3 engine
|
|
143
|
-
| [`sfmc/ssjs-no-nonfunctional-method`](docs/rules/ssjs/no-nonfunctional-method.md) | `warn` | Flag Core Library methods that never take effect at runtime
|
|
144
|
-
| [`sfmc/ssjs-prefer-parsejson-safe-arg`](docs/rules/ssjs/prefer-parsejson-safe-arg.md) | `warn` | Require string coercion on `ParseJSON` argument
|
|
145
|
-
| [`sfmc/ssjs-no-switch-default`](docs/rules/ssjs/no-switch-default.md) | `warn` | Disallow `default` clause in `switch` statements
|
|
146
|
-
| [`sfmc/ssjs-no-treatascontent-injection`](docs/rules/ssjs/no-treatascontent-injection.md) | `warn` | Flag dynamic string concatenation in `TreatAsContent` calls
|
|
147
|
-
| [`sfmc/ssjs-core-method-arity`](docs/rules/ssjs/core-method-arity.md) | `warn` | Enforce correct argument counts for Core Library object methods
|
|
148
|
-
| [`sfmc/ssjs-arg-types`](docs/rules/ssjs/arg-types.md) | `warn` | Check that literal arguments match expected parameter types
|
|
132
|
+
| [`sfmc/ssjs-no-nonexistent-global`](docs/rules/ssjs/no-nonexistent-global.md) | `error` | Flag documented SSJS globals that throw ReferenceError at runtime |
|
|
133
|
+
| [`sfmc/ssjs-no-property-call`](docs/rules/ssjs/no-property-call.md) | `error` | Disallow calling Platform.Request/Response properties as functions |
|
|
134
|
+
| [`sfmc/ssjs-no-clr-header-access`](docs/rules/ssjs/no-clr-header-access.md) | `error` | Disallow CLR-unsafe reads of `HttpResponse.headers`; read via `for..in` |
|
|
135
|
+
| [`sfmc/ssjs-require-string-clr-content`](docs/rules/ssjs/require-string-clr-content.md) | `error` | Require wrapping `HttpResponse.content` with `String()` before use |
|
|
136
|
+
| [`sfmc/ssjs-platform-function-arity`](docs/rules/ssjs/platform-function-arity.md) | `error` | Enforce correct arity for `Platform.Function.*` |
|
|
137
|
+
| [`sfmc/ssjs-require-platform-load-order`](docs/rules/ssjs/require-platform-load-order.md) | `error` | Require `Platform.Load()` before Core usage in order |
|
|
138
|
+
| [`sfmc/ssjs-no-hardcoded-credentials`](docs/rules/ssjs/no-hardcoded-credentials.md) | `error` | Flag hardcoded keys in encryption calls |
|
|
139
|
+
| [`sfmc/ssjs-cache-loop-length`](docs/rules/ssjs/cache-loop-length.md) | `warn` | Require caching `.length` in for-loops |
|
|
140
|
+
| [`sfmc/ssjs-require-hasownproperty`](docs/rules/ssjs/require-hasownproperty.md) | `warn` | Require `hasOwnProperty` guard in for-in loops |
|
|
141
|
+
| [`sfmc/ssjs-prefer-platform-load-version`](docs/rules/ssjs/prefer-platform-load-version.md) | `warn` | Enforce a minimum `Platform.Load` version string |
|
|
142
|
+
| [`sfmc/ssjs-no-unavailable-method`](docs/rules/ssjs/no-unavailable-method.md) | `warn` | Flag Array/String methods unavailable or broken in SFMC's ES3 engine |
|
|
143
|
+
| [`sfmc/ssjs-no-nonfunctional-method`](docs/rules/ssjs/no-nonfunctional-method.md) | `warn` | Flag Core Library methods that never take effect at runtime |
|
|
144
|
+
| [`sfmc/ssjs-prefer-parsejson-safe-arg`](docs/rules/ssjs/prefer-parsejson-safe-arg.md) | `warn` | Require string coercion on `ParseJSON` argument |
|
|
145
|
+
| [`sfmc/ssjs-no-switch-default`](docs/rules/ssjs/no-switch-default.md) | `warn` | Disallow `default` clause in `switch` statements |
|
|
146
|
+
| [`sfmc/ssjs-no-treatascontent-injection`](docs/rules/ssjs/no-treatascontent-injection.md) | `warn` | Flag dynamic string concatenation in `TreatAsContent` calls |
|
|
147
|
+
| [`sfmc/ssjs-core-method-arity`](docs/rules/ssjs/core-method-arity.md) | `warn` | Enforce correct argument counts for Core Library object methods |
|
|
148
|
+
| [`sfmc/ssjs-arg-types`](docs/rules/ssjs/arg-types.md) | `warn` | Check that literal arguments match expected parameter types |
|
|
149
149
|
|
|
150
150
|
## Handlebars Rules (`hbs-*`)
|
|
151
151
|
|
|
@@ -165,16 +165,16 @@ Email HTML for SFMC frequently contains **Outlook conditional comments** (`<!--[
|
|
|
165
165
|
|
|
166
166
|
The MSO rules are **auto-included** in the HTML-embedded configs: `embedded`, `strict`, `embedded-next`, and `strict-next`. When you lint an `.html` file with any of these, the combined `sfmc/sfmc` processor also extracts MSO conditional comments and the document body and runs the MSO rules on them — no extra processor or config to wire up, and no processor conflict.
|
|
167
167
|
|
|
168
|
-
| Rule (`mso/*`)
|
|
169
|
-
|
|
|
170
|
-
| [`mso/valid-mso-condition`](https://github.com/JoernBerkefeld/eslint-plugin-mso-email/blob/main/docs/rules/valid-mso-condition.md)
|
|
171
|
-
| [`mso/matching-mso-endif`](https://github.com/JoernBerkefeld/eslint-plugin-mso-email/blob/main/docs/rules/matching-mso-endif.md)
|
|
172
|
-
| [`mso/matching-mso-endif-type`](https://github.com/JoernBerkefeld/eslint-plugin-mso-email/blob/main/docs/rules/matching-mso-endif-type.md)
|
|
173
|
-
| [`mso/no-unknown-mso-property`](https://github.com/JoernBerkefeld/eslint-plugin-mso-email/blob/main/docs/rules/no-unknown-mso-property.md)
|
|
174
|
-
| [`mso/vml-requires-namespace`](https://github.com/JoernBerkefeld/eslint-plugin-mso-email/blob/main/docs/rules/vml-requires-namespace.md)
|
|
175
|
-
| [`mso/no-unknown-vml-tag`](https://github.com/JoernBerkefeld/eslint-plugin-mso-email/blob/main/docs/rules/no-unknown-vml-tag.md)
|
|
176
|
-
| [`mso/no-unknown-vml-attribute`](https://github.com/JoernBerkefeld/eslint-plugin-mso-email/blob/main/docs/rules/no-unknown-vml-attribute.md) | `warn`
|
|
177
|
-
| [`mso/table-presentation-role`](https://github.com/JoernBerkefeld/eslint-plugin-mso-email/blob/main/docs/rules/table-presentation-role.md)
|
|
168
|
+
| Rule (`mso/*`) | Default (embedded/strict) | Description |
|
|
169
|
+
| -------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------- | ----------------------------------------------------------- |
|
|
170
|
+
| [`mso/valid-mso-condition`](https://github.com/JoernBerkefeld/eslint-plugin-mso-email/blob/main/docs/rules/valid-mso-condition.md) | `error` | Validate the `[if …]` expression syntax of MSO comments |
|
|
171
|
+
| [`mso/matching-mso-endif`](https://github.com/JoernBerkefeld/eslint-plugin-mso-email/blob/main/docs/rules/matching-mso-endif.md) | `error` | Require every MSO opener to have a matching `<![endif]>` |
|
|
172
|
+
| [`mso/matching-mso-endif-type`](https://github.com/JoernBerkefeld/eslint-plugin-mso-email/blob/main/docs/rules/matching-mso-endif-type.md) | `warn` | Require the endif comment style to match its opener |
|
|
173
|
+
| [`mso/no-unknown-mso-property`](https://github.com/JoernBerkefeld/eslint-plugin-mso-email/blob/main/docs/rules/no-unknown-mso-property.md) | `warn` | Flag unknown `mso-*` CSS properties |
|
|
174
|
+
| [`mso/vml-requires-namespace`](https://github.com/JoernBerkefeld/eslint-plugin-mso-email/blob/main/docs/rules/vml-requires-namespace.md) | `warn` | Require the `v:` VML namespace declaration when VML is used |
|
|
175
|
+
| [`mso/no-unknown-vml-tag`](https://github.com/JoernBerkefeld/eslint-plugin-mso-email/blob/main/docs/rules/no-unknown-vml-tag.md) | `warn` | Flag unknown `v:*` VML tags |
|
|
176
|
+
| [`mso/no-unknown-vml-attribute`](https://github.com/JoernBerkefeld/eslint-plugin-mso-email/blob/main/docs/rules/no-unknown-vml-attribute.md) | `warn` | Flag unknown attributes on VML tags |
|
|
177
|
+
| [`mso/table-presentation-role`](https://github.com/JoernBerkefeld/eslint-plugin-mso-email/blob/main/docs/rules/table-presentation-role.md) | `warn` | Require `role="presentation"` on layout tables |
|
|
178
178
|
|
|
179
179
|
Severities above are the same in `embedded`, `strict`, `embedded-next`, and `strict-next` (MSO markup is engine-agnostic — it behaves identically for Engagement and Next). For MSO rule details and options, see the [`eslint-plugin-mso-email` docs](https://github.com/JoernBerkefeld/eslint-plugin-mso-email).
|
|
180
180
|
|
|
@@ -191,27 +191,27 @@ import sfmc from 'eslint-plugin-sfmc';
|
|
|
191
191
|
import eslintPluginUnicorn from 'eslint-plugin-unicorn';
|
|
192
192
|
|
|
193
193
|
export default [
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
194
|
+
eslintPluginUnicorn.configs.recommended, // you opt in — registers the `unicorn` plugin
|
|
195
|
+
...sfmc.configs.recommended,
|
|
196
|
+
...sfmc.configs.embedded, // AMPscript + SSJS embedded in HTML (<script runat="server">)
|
|
197
|
+
...sfmc.configs['unicorn-ssjs'], // OPTIONAL: off the 46 SFMC-incompatible unicorn rules for SSJS
|
|
198
|
+
...sfmc.configs['unicorn-ssjs-embedded'], // OPTIONAL: same override for SSJS embedded in HTML (<script runat="server">)
|
|
199
199
|
];
|
|
200
200
|
```
|
|
201
201
|
|
|
202
|
-
| Config
|
|
203
|
-
|
|
|
204
|
-
| `sfmc.configs['unicorn-ssjs']`
|
|
205
|
-
| `sfmc.configs['unicorn-ssjs-embedded']` | `**/*.html/*.js`
|
|
202
|
+
| Config | Files | What it does |
|
|
203
|
+
| --------------------------------------- | ---------------- | --------------------------------------------------------- |
|
|
204
|
+
| `sfmc.configs['unicorn-ssjs']` | `**/*.ssjs` | Turns off the 46 SFMC-incompatible unicorn rules for SSJS |
|
|
205
|
+
| `sfmc.configs['unicorn-ssjs-embedded']` | `**/*.html/*.js` | Same 46-rule override for SSJS embedded in HTML |
|
|
206
206
|
|
|
207
207
|
Only **46** of unicorn's 300 recommended rules are overridden — the other **254** stay active. If you don't use unicorn, omit these configs entirely. For the full rule-by-rule breakdown (with rationale and SFMC evidence links, pinned to unicorn v71.1.0), see [docs/unicorn-compatibility.md](docs/unicorn-compatibility.md).
|
|
208
208
|
|
|
209
209
|
## Processors
|
|
210
210
|
|
|
211
|
-
| Processor | Purpose
|
|
212
|
-
| ---------------- |
|
|
213
|
-
| `sfmc/ampscript` | Extract `%%[ ]%%`, `%%= =%%`, `<script language="ampscript">`
|
|
214
|
-
| `sfmc/ssjs` | Extract `<script runat="server">` (non-ampscript)
|
|
211
|
+
| Processor | Purpose |
|
|
212
|
+
| ---------------- | ----------------------------------------------------------------- |
|
|
213
|
+
| `sfmc/ampscript` | Extract `%%[ ]%%`, `%%= =%%`, `<script language="ampscript">` |
|
|
214
|
+
| `sfmc/ssjs` | Extract `<script runat="server">` (non-ampscript) |
|
|
215
215
|
| `sfmc/sfmc` | Combined: extracts AMPscript, SSJS, Handlebars, and MSO from HTML |
|
|
216
216
|
|
|
217
217
|
## License
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-sfmc",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.9.0",
|
|
4
4
|
"description": "ESLint plugin for Salesforce Marketing Cloud Engagement+Next - AMPscript, Server-Side JavaScript (SSJS) and Handlebars",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@handlebars/parser": "^2.2.2",
|
|
40
|
-
"ampscript-data": "^3.
|
|
41
|
-
"ampscript-parser": "^0.
|
|
40
|
+
"ampscript-data": "^3.1.0",
|
|
41
|
+
"ampscript-parser": "^0.3.0",
|
|
42
42
|
"eslint-plugin-mso-email": "^2.0.0",
|
|
43
43
|
"handlebars-data": "^0.3.0",
|
|
44
44
|
"mso-conditional-parser": "^2.0.1",
|
package/src/ampscript-parser.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Suggests wrapping
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Suggests wrapping custom personalization strings in `AttributeValue("...")`
|
|
3
|
+
* to prevent send-aborting errors when the attribute is missing from the
|
|
4
|
+
* subscriber context. Applies to both bare identifiers (e.g. `FirstName`) and
|
|
5
|
+
* bracket notation (e.g. `[First Name]`).
|
|
5
6
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* Known Marketing Cloud system personalization strings (e.g. `_subscriberkey`,
|
|
8
|
+
* `emailaddr`, `[MSG(0).NOUN(0)]`) are exempt in either form. Only flags nodes
|
|
9
|
+
* that appear directly in SetStatement values or as standalone
|
|
10
|
+
* ExpressionStatements — contexts where a bare attribute reference is likely
|
|
11
|
+
* intentional data access rather than a function name.
|
|
10
12
|
*/
|
|
11
13
|
|
|
12
|
-
import { functionNames } from 'ampscript-data';
|
|
14
|
+
import { functionNames, isSystemPersonalizationString } from 'ampscript-data';
|
|
13
15
|
|
|
14
16
|
const AMPSCRIPT_KEYWORDS = new Set([
|
|
15
17
|
'var',
|
|
@@ -31,15 +33,35 @@ const AMPSCRIPT_KEYWORDS = new Set([
|
|
|
31
33
|
'false',
|
|
32
34
|
]);
|
|
33
35
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Returns the attribute name a node refers to when it is a candidate for the
|
|
38
|
+
* AttributeValue() suggestion, or null when the node should be ignored (a
|
|
39
|
+
* function name, keyword, or known system personalization string).
|
|
40
|
+
*
|
|
41
|
+
* @param {object} node - AMPscript AST node to inspect.
|
|
42
|
+
* @returns {string | null} The attribute name to wrap, or null.
|
|
43
|
+
*/
|
|
44
|
+
function personalizationName(node) {
|
|
45
|
+
if (!node) {
|
|
46
|
+
return null;
|
|
37
47
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
48
|
+
if (node.type === 'Identifier') {
|
|
49
|
+
const lower = node.value.toLowerCase();
|
|
50
|
+
if (functionNames.has(lower) || AMPSCRIPT_KEYWORDS.has(lower)) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
if (isSystemPersonalizationString(node.value)) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
return node.value;
|
|
57
|
+
}
|
|
58
|
+
if (node.type === 'PersonalizationString') {
|
|
59
|
+
if (isSystemPersonalizationString(node.value)) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
return node.value;
|
|
41
63
|
}
|
|
42
|
-
return
|
|
64
|
+
return null;
|
|
43
65
|
}
|
|
44
66
|
|
|
45
67
|
export default {
|
|
@@ -60,20 +82,20 @@ export default {
|
|
|
60
82
|
},
|
|
61
83
|
|
|
62
84
|
create(context) {
|
|
63
|
-
function reportWithSuggestion(
|
|
85
|
+
function reportWithSuggestion(node, name) {
|
|
86
|
+
// Escape embedded double quotes so the generated
|
|
87
|
+
// AttributeValue("…") call stays syntactically valid.
|
|
88
|
+
const escaped = name.replaceAll('"', String.raw`\"`);
|
|
64
89
|
context.report({
|
|
65
|
-
node
|
|
90
|
+
node,
|
|
66
91
|
messageId: 'preferAttributeValue',
|
|
67
|
-
data: { name
|
|
92
|
+
data: { name },
|
|
68
93
|
suggest: [
|
|
69
94
|
{
|
|
70
95
|
messageId: 'wrapWithAttributeValue',
|
|
71
|
-
data: { name
|
|
96
|
+
data: { name },
|
|
72
97
|
fix(fixer) {
|
|
73
|
-
return fixer.replaceText(
|
|
74
|
-
identifierNode,
|
|
75
|
-
`AttributeValue("${identifierNode.value}")`,
|
|
76
|
-
);
|
|
98
|
+
return fixer.replaceText(node, `AttributeValue("${escaped}")`);
|
|
77
99
|
},
|
|
78
100
|
},
|
|
79
101
|
],
|
|
@@ -82,14 +104,16 @@ export default {
|
|
|
82
104
|
|
|
83
105
|
return {
|
|
84
106
|
SetStatement(node) {
|
|
85
|
-
|
|
86
|
-
|
|
107
|
+
const name = personalizationName(node.value);
|
|
108
|
+
if (name !== null) {
|
|
109
|
+
reportWithSuggestion(node.value, name);
|
|
87
110
|
}
|
|
88
111
|
},
|
|
89
112
|
|
|
90
113
|
AmpExpressionStatement(node) {
|
|
91
|
-
|
|
92
|
-
|
|
114
|
+
const name = personalizationName(node.expression);
|
|
115
|
+
if (name !== null) {
|
|
116
|
+
reportWithSuggestion(node.expression, name);
|
|
93
117
|
}
|
|
94
118
|
},
|
|
95
119
|
};
|