🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

eslint-plugin-sfmc

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-sfmc

ESLint plugin for Salesforce Marketing Cloud Engagement+Next - AMPscript, Server-Side JavaScript (SSJS) and Handlebars

latest
Source
npmnpm
Version
4.9.1
Version published
Weekly downloads
425
-58.82%
Maintainers
1
Weekly downloads
 
Created
Source

eslint-plugin-sfmc

Unified ESLint plugin for Salesforce Marketing Cloud — linting rules for both AMPscript and Server-Side JavaScript (SSJS).

Installation

npm install eslint-plugin-sfmc --save-dev

Requires ESLint 9+ (flat config).

Quick Start

// eslint.config.js
import sfmc from 'eslint-plugin-sfmc';

export default [
  // Lint standalone .ampscript/.amp and .ssjs files
  ...sfmc.configs.recommended,

  // Lint AMPscript + SSJS embedded in .html files
  ...sfmc.configs.embedded,
];

VS Code Setup

To see eslint(sfmc/...) diagnostics in VS Code for .amp, .ssjs, and .html files you need the VS Code ESLint extension to validate the custom SFMC language IDs.

Option A — Install vscode-sfmc-language (recommended)

The SFMC Language Service extension contributes the SFMC language IDs and automatically configures eslint.validate for you. No manual settings required.

Option B — Manual configuration

Add the following to your .vscode/settings.json:

{
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    "typescript",
    "typescriptreact",
    "html",
    "vue",
    "markdown",
    "ampscript",
    "ssjs",
    "sfmc",
    "handlebars"
  ]
}

Why eslint.validate and not eslint.probe? eslint.probe silently skips files for language IDs that the ESLint extension does not natively recognise. eslint.validate forces the extension to process those files regardless of language ID.

Configs

Marketing Cloud Engagement (default)

ConfigFilesWhat it does
sfmc.configs.ampscript**/*.ampscript, **/*.ampAMPscript rules only (recommended severity)
sfmc.configs.ssjs**/*.ssjsSSJS rules only (recommended severity)
sfmc.configs.recommendedBoth of the aboveAll rules at recommended severity for standalone files
sfmc.configs.embedded**/*.htmlCombined processor extracts both languages from HTML
sfmc.configs.strictAll of the above + HTMLAll rules at error severity for standalone and embedded

recommended, embedded, and strict are arrays — spread them with ....

Marketing Cloud Next

Use the -next config variants when targeting Marketing Cloud Next (MCN). MCN supports only a subset of AMPscript functions and does not support SSJS at all. Handlebars is MCN's templating language, so the -next configs also lint the {{...}} helpers and {!$...} bindings extracted from HTML and standalone .hbs files (see Handlebars Rules).

ConfigFilesWhat it does
sfmc.configs['ampscript-next']**/*.ampscript, **/*.ampAMPscript rules + flags functions unsupported in MCN (single config object)
sfmc.configs['ssjs-next']**/*.ssjsFlags all SSJS API calls as MCN-unsupported; all other SSJS quality rules disabled
sfmc.configs['recommended-next']Both of the above + **/*.hbsAMPscript MCN-aware + SSJS flagged + Handlebars rules for standalone .hbs files
sfmc.configs['embedded-next']**/*.html, **/*.hbsAMPscript MCN-aware + SSJS flagged + Handlebars rules for HTML-embedded code and .hbs
sfmc.configs['strict-next']All of the above + HTML + **/*.hbsAll AMPscript rules at error severity + MCN flag; SSJS fully flagged; Handlebars rules on

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.

recommended-next, embedded-next, and strict-next are arrays — spread them with ....

// eslint.config.js — targeting Marketing Cloud Next
import sfmc from 'eslint-plugin-sfmc';

export default [...sfmc.configs['recommended-next'], ...sfmc.configs['embedded-next']];

AMPscript Rules (amp-*)

RuleDefaultDescription
sfmc/amp-no-unknown-functionerrorDisallow calls to unknown AMPscript functions
sfmc/amp-no-mcn-unsupportedoff (error in -next)Flag AMPscript functions unavailable in the targeted MCN API version (apiVersion)
sfmc/amp-function-arityerrorEnforce correct argument counts
sfmc/amp-arg-typeserrorCheck that literal arguments match expected parameter types and allowed values
sfmc/amp-set-requires-targeterrorRequire set to have a target variable
sfmc/amp-no-smart-quoteserrorDisallow smart/curly quotes in strings
sfmc/amp-no-var-redeclarationwarnDisallow re-declaring a variable with var
sfmc/amp-no-empty-blockwarnDisallow empty %%[ ]%% blocks
sfmc/amp-no-loop-counter-assignwarnDisallow assigning to the for loop counter
sfmc/amp-no-inline-statementwarnDisallow statements inside inline expressions
sfmc/amp-no-deprecated-functionwarnFlag deprecated functions and suggest replacements
sfmc/amp-naming-conventionwarnEnforce variable naming convention
sfmc/amp-no-empty-thenwarnDisallow IF with empty THEN branch
sfmc/amp-require-rowcount-checkwarnRequire RowCount check before FOR on LookupRows
sfmc/amp-no-html-commentwarnDisallow HTML comments inside AMPscript blocks
sfmc/amp-no-js-line-commentwarnDisallow JS-style // line comments in AMPscript
sfmc/amp-no-nested-script-tagerrorDisallow <script> tags nested inside AMPscript script tags
sfmc/amp-no-nested-ampscript-delimitererrorDisallow AMPscript delimiters nested inside AMPscript blocks
sfmc/amp-prefer-attribute-valueoffPrefer AttributeValue() over bare personalization
sfmc/amp-require-variable-declarationoffRequire var before set
sfmc/amp-no-email-excluded-functionoffFlag functions unavailable in email context

SSJS Rules (ssjs-*)

RuleDefaultDescription
sfmc/ssjs-require-platform-loaderrorRequire Platform.Load("core") before Core or requiresCoreLoad globals
sfmc/ssjs-no-unsupported-syntaxerrorFlag ES6+ syntax not supported by SFMC
sfmc/ssjs-no-unknown-functionerrorDisallow unknown methods on Platform.*, HTTP, Core Library, and WSProxy
sfmc/ssjs-no-mcn-unsupportedoff (error in -next)Flag all SSJS API usage as unsupported in Marketing Cloud Next
sfmc/ssjs-no-deprecated-functionerrorFlag use of deprecated SFMC SSJS APIs (Classic Content classes, ErrorUtil)
sfmc/ssjs-no-nonexistent-globalerrorFlag documented SSJS globals that throw ReferenceError at runtime
sfmc/ssjs-no-property-callerrorDisallow calling Platform.Request/Response properties as functions
sfmc/ssjs-no-clr-header-accesserrorDisallow CLR-unsafe reads of HttpResponse.headers; read via for..in
sfmc/ssjs-require-string-clr-contenterrorRequire wrapping HttpResponse.content with String() before use
sfmc/ssjs-platform-function-arityerrorEnforce correct arity for Platform.Function.*
sfmc/ssjs-require-platform-load-ordererrorRequire Platform.Load() before Core usage in order
sfmc/ssjs-no-hardcoded-credentialserrorFlag hardcoded keys in encryption calls
sfmc/ssjs-cache-loop-lengthwarnRequire caching .length in for-loops
sfmc/ssjs-require-hasownpropertywarnRequire hasOwnProperty guard in for-in loops
sfmc/ssjs-prefer-platform-load-versionwarnEnforce a minimum Platform.Load version string
sfmc/ssjs-no-unavailable-methodwarnFlag Array/String methods unavailable or broken in SFMC's ES3 engine
sfmc/ssjs-no-nonfunctional-methodwarnFlag Core Library methods that never take effect at runtime
sfmc/ssjs-prefer-parsejson-safe-argwarnRequire string coercion on ParseJSON argument
sfmc/ssjs-no-switch-defaultwarnDisallow default clause in switch statements
sfmc/ssjs-no-treatascontent-injectionwarnFlag dynamic string concatenation in TreatAsContent calls
sfmc/ssjs-core-method-aritywarnEnforce correct argument counts for Core Library object methods
sfmc/ssjs-arg-typeswarnCheck that literal arguments match expected parameter types

Handlebars Rules (hbs-*)

Handlebars is the templating language for Marketing Cloud Next (MCN) only. These rules are enabled at error severity in the -next configs — applied both to {{...}} extracted from HTML and to standalone .hbs files — and are off in the classic (Engagement) configs — in classic SFMC, {{...}} is plain content and must not be flagged.

RuleDefault (-next)Description
sfmc/hbs-no-unknown-helpererrorDisallow helper invocations that are not part of the MCN catalog
sfmc/hbs-no-unknown-bindingerrorDisallow unknown {!$...} built-in data bindings
sfmc/hbs-helper-arityerrorEnforce correct positional-argument counts for known helpers
sfmc/hbs-no-unsupported-constructerrorDisallow constructs unsupported by the MCN engine (partials, decorators, log)
sfmc/hbs-no-mcn-unsupportederrorFlag helpers and bindings unavailable in the targeted MCN API version (apiVersion)

MSO / Outlook email checks

Email HTML for SFMC frequently contains Outlook conditional comments (<!--[if mso]>…<![endif]-->), MSO-only CSS, and VML fallbacks. These checks are provided by eslint-plugin-mso-email, which ships as a bundled dependency of eslint-plugin-sfmc — you do not load it separately.

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.

Rule (mso/*)Default (embedded/strict)Description
mso/valid-mso-conditionerrorValidate the [if …] expression syntax of MSO comments
mso/matching-mso-endiferrorRequire every MSO opener to have a matching <![endif]>
mso/matching-mso-endif-typewarnRequire the endif comment style to match its opener
mso/no-unknown-mso-propertywarnFlag unknown mso-* CSS properties
mso/vml-requires-namespacewarnRequire the v: VML namespace declaration when VML is used
mso/no-unknown-vml-tagwarnFlag unknown v:* VML tags
mso/no-unknown-vml-attributewarnFlag unknown attributes on VML tags
mso/table-presentation-rolewarnRequire role="presentation" on layout tables

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.

Using eslint-plugin-unicorn with SFMC

eslint-plugin-unicorn is a high-quality, widely used plugin that we strongly recommend — but it is built for modern JavaScript, not SFMC's SSJS runtime. SFMC SSJS runs on a JINT-based ES3/ES5-era engine that lacks many built-ins (Array#includes, String#startsWith, Set, Map, Object.fromEntries, Math.trunc, spread ..., ES modules, async/await, …).

If you enable unicorn's recommended set on SSJS, about 46 of its 308 recommended rules would either autofix your code to a missing built-in (breaking it at runtime) or forbid a required SFMC workaround. eslint-plugin-sfmc offers an optional override config that turns off exactly those 46 rules for SSJS.

Important — this is optional and only needed if you use unicorn. eslint-plugin-sfmc does not depend on or load unicorn. The override configs are plain rules objects with no plugins key, so they only resolve when your own unicorn config (which registers the unicorn plugin) is loaded earlier in the flat-config array. Spread the sfmc override after it:

import sfmc from 'eslint-plugin-sfmc';
import eslintPluginUnicorn from 'eslint-plugin-unicorn';

export default [
  eslintPluginUnicorn.configs.recommended, // you opt in — registers the `unicorn` plugin
  ...sfmc.configs.recommended,
  ...sfmc.configs.embedded, // AMPscript + SSJS embedded in HTML (<script runat="server">)
  ...sfmc.configs['unicorn-ssjs'], // OPTIONAL: off the 46 SFMC-incompatible unicorn rules for SSJS
  ...sfmc.configs['unicorn-ssjs-embedded'], // OPTIONAL: same override for SSJS embedded in HTML (<script runat="server">)
];
ConfigFilesWhat it does
sfmc.configs['unicorn-ssjs']**/*.ssjsTurns off the 46 SFMC-incompatible unicorn rules for SSJS
sfmc.configs['unicorn-ssjs-embedded']**/*.html/*.jsSame 46-rule override for SSJS embedded in HTML

Only 46 of unicorn's 308 recommended rules are overridden — the other 262 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 v73.0.0), see docs/unicorn-compatibility.md.

Processors

ProcessorPurpose
sfmc/ampscriptExtract %%[ ]%%, %%= =%%, <script language="ampscript">
sfmc/ssjsExtract <script runat="server"> (non-ampscript)
sfmc/sfmcCombined: extracts AMPscript, SSJS, Handlebars, and MSO from HTML

License

MIT

Keywords

eslint

FAQs

Package last updated on 04 Aug 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts