5.43.9 • Published 1 year ago

isml-linter v5.43.9

Weekly downloads
2,489
License
MIT
Repository
github
Last release
1 year ago

ISML Linter

ISML Linter is a tool for examining if your project's templates follow a specified set of rules defined by your dev team. The available rules can be roughly grouped into:

  • Styles that are defined by your team;
  • Syntactic errors related to <is* > tags;
  • Coding conventions recommended by Salesforce;
  • Git conflicts that may accidentally be left unresolved;

Please feel free to make suggestions and help make this linter better. :) The set of currently available rules can be found below.

ISML Linter is also available as a VSCode extension, give it a try!

Installation

Prerequisite: Node.js (>=10.0.0).

Simply run in your project's root directory:

$ npm install isml-linter --save-dev

and add the following to package.json:

"scripts": {
    "init:isml":  "./node_modules/.bin/isml-linter --init",
    "lint:isml":  "./node_modules/.bin/isml-linter",
    "build:isml": "./node_modules/.bin/isml-linter --build",
    "fix:isml":   "./node_modules/.bin/isml-linter --autofix"
}

Here's what each script does:

  • init:isml creates a config file;
  • lint:isml simply lists the broken rules in the console;
  • build:isml raises an error if there is any broken rule, thus can be used in your build process;
  • fix:isml applies fixes for the enabled rules;

Configuration

After adding the above scripts to package.json, run the following command to generate a config file containing all available rules:

npm run init:isml

Alternatively, you can manually create a configuration file, make sure it is in the project root directory and has one of the following names: ismllinter.config.js, .ismllintrc.js or .ismllinter.json.

You can disable any rule by removing it from the config file. You may also find these configuration options useful:

ConfigDescription
rootDirThe root directory under which the linter will run. Defaults to the directory where the package.json file is
disableHtml5Disallows HTML5-defined unclosed tags, such as input, img and meta. Default: false
ignoreUnparseableDoes not raise an error if an unparsable template is found. Default: false. Please check "Parse Modes - Tree" section below
ignoreIf a template path contains (as a substring) any string defined here, that template will be ignored by the linter
indentDeprecated Please check indent docs. Indentation size. Default: 4
linebreakStyleunix or windows. Default: unix
eslintConfigPath to a eslint configuration file, to be applied within <isscript> tags. Default: .eslintrc.json
enableCacheDeprecated Please check cache docs. Default: false
autoFixApplies fixes for enabled rules. Default: false
printPartialResultsLimits issues or rule occurrences listed in the console to up to 30 items. Useful to get overall picture in case of many errors. Default: false
verboseProvides additional details of the linting process in the console. Default: false
disableTreeParseEnables only rules that do not depend on building an ISML tree. Check below when this might be useful. Default: false
rulesDefines which rules to check. See available rules below

Note: If you explicitly set "ignoreUnparseable" config to true, unparsable templates may contain errors that will not be detected by ISML Linter.

Example configuration:

{
    "rootDir": "./cartridges",
    "ignore": [
        "this_directory_is_to_be_ignored"
        "Email.isml"
    ],
    "rules" : {
        "no-br" : {}, 
        "enforce-require" : {}
    }
}

Note that according to the above configurations, the following templates would be ignored by ISML Linter:

  • registerEmail.isml
  • some/path/welcomeEmail.isml
  • this_directory_is_to_be_ignored/producttile.isml
  • some/path/this_directory_is_to_be_ignored/confirmationpage.isml

Parse Modes

Tree (disableTreeParse : false)

This is the default, and most powerful mode. It analyses the template and tries to build an "ISML DOM" tree to then apply the enabled rules. It is required that the template is parsable.

For example, if a template contains a snippet like the following, IT IS NOT considered a parsable template:

<isif condition="${aCondition}">
    <div class="info">
</isif>
        Some content
<isif condition="${aCondition}">
    </div>
</isif>

since the linter is not able to make an association between the opening and the corresponding closing <div> elements. This is the only known limitation for this parse mode. One possible solution to turn such templates into parsable is to replace that snippet by:

<isif condition="${aCondition}">
    <div class="info">
        <isinclude template="myTemplate" />
    </div>
<iselse/>
    <isinclude template="myTemplate" />
</isif>

There are other possible, potentially more "best practice" approaches, but it goes beyond the scope of this article.

And, to avoid possible doubts, here is an extra piece of information: it is allowed to have ISML tags within HTML tags, such as:

<div <isif ...> </isif> />

Line by Line (disableTreeParse : true)

This is a more robust, less powerful mode. It only has a few set of rules available and is indicated for cases where there are many, many lint errors and you want fix them gradually. It is also recommended in cases you don't want to force templates to be parsable (see previous section). This mode is ideally temporary, as it cannot take advantages of even some simple rules, such as indentation checking.

Command Line Interface

Please check CLI docs.

Git Hooks (Optional)

To prevent new errors to be introduced in next pushes, we recommend using some git hook npm package, such as husky or ghooks. The following example works for ghook:

"config": {
    "ghooks": {
      "pre-push": "npm run build:isml"
    }
}

API

Check the API docs.

Available Rules

Please check the Generic Configurations for Rules page.

RuleDescription
:exclamation: no-brDeprecated Disallows <br/> tags. Enable this rule if you prefer to use CSS to handle vertical spacing
no-git-conflictDisallows unresolved Git conflicts
no-import-packageDisallows importPackage() function. It is recommended by Salesforce to use require() instead
:exclamation: no-isscriptDeprecated Disallows <isscript/> tag in template. Enable this rule if you prefer logic to be kept in a separate .ds/.js file
:wrench: no-trailing-spacesDisallows trailing blank spaces
:wrench: no-space-only-linesDisallows lines that contain only blank spaces, i.e., unnecessarily indented
no-inline-styleDisallows use of style HTML attribute. Enable this rule if you prefer style to be fully handled via CSS
:wrench: no-tabsDisallows use of tabs
enforce-isprint[KNOWN BUG] Enforces every ${string} to be wrapped by an <isprint/> tag
enforce-requireDisallows direct calls to a DigitalScript class, such as in:var PaymentMgr = dw.order.PaymentMgr;For this case, it is recommended to use instead:var PaymentMgr = require('dw/order/PaymentMgr');
lowercase-filenameDisallows template names to have uppercase characters
max-linesLimits the size of templates
:small_orange_diamond: no-hardcodeDisallows hardcoded strings outside ISML expressions
:wrench: :small_orange_diamond: indentSets indentation size
:small_orange_diamond: no-require-in-loopNo require() calls from within a loop in the template
:small_orange_diamond: no-embedded-ismlDisallows embedded isml tags, such as in <div <isif /> />, except for <isprint />
:small_orange_diamond: max-depthSets the maximum of nested elements in a template
:small_orange_diamond: disallow-tagsDisallows tags specified at rule level
:small_orange_diamond: one-element-per-lineOne element per line
:wrench: :small_orange_diamond: leading-iscontentEnsures <iscontent> tag is the first element in the template if present
:wrench: :small_orange_diamond: leading-iscacheEnsures <iscache> tag is among the first element in the template if present
:small_orange_diamond: no-deprecated-attrsDisallows deprecated attributes or attribute values
:small_orange_diamond: contextual-attrsDisallows presence of mutually exclusive attributes
:small_orange_diamond: custom-tagsChecks if "util/modules" template is actually needed or if it is missing
:wrench: :small_orange_diamond: eslint-to-isscriptApplies ESLint rules to <isscript> tag content
:wrench: :small_orange_diamond: no-iselse-slashDisallows self-closing <iselse> and <iselseif> tags
:small_orange_diamond: empty-eofEnforces a empty line at the end of the template
:small_orange_diamond: align-issetAligns contiguous <isset> tags attributes' columns
:small_orange_diamond: enforce-securityEnforces security measures
:wrench: :small_orange_diamond: no-redundant-contextPrevents use of unnecessary contexts, such as dw.web.Resource
:small_orange_diamond: strict-void-elementsDisallows closing tags for void elements, such as <input> and <img>

You are more than welcome to contribute with us! Please check the contribute section.

Donations

This project was conceived by its author without any financial support, with the intention to help the community improving and speeding up any projects that involve ISML templates. If you think ISML Linter has helped you and your team, please consider making a donation, it will be much appreciated!

npm.io

Iconography

:exclamation: Deprecated feature :boom: New feature :small_orange_diamond: Rules that require "disableTreeParse" configuration not to be true. :wrench: Auto-fix available

5.43.8

1 year ago

5.43.9

1 year ago

5.43.6

1 year ago

5.43.7

1 year ago

5.43.4

1 year ago

5.43.5

1 year ago

5.43.3

1 year ago

5.42.3

1 year ago

5.42.4

1 year ago

5.42.1

1 year ago

5.42.2

1 year ago

5.42.0

1 year ago

5.43.2

1 year ago

5.43.0

1 year ago

5.43.1

1 year ago

5.40.5

1 year ago

5.40.4

1 year ago

5.41.0

1 year ago

5.40.3

2 years ago

5.40.1

2 years ago

5.40.2

2 years ago

5.39.4

2 years ago

5.40.0

2 years ago

5.39.3

3 years ago

5.39.2

3 years ago

5.39.1

3 years ago

5.39.0

3 years ago

5.38.4

3 years ago

5.38.5

3 years ago

5.38.3

3 years ago

5.38.2

3 years ago

5.38.0

3 years ago

5.38.1

3 years ago

5.37.0

3 years ago

5.36.5

3 years ago

5.36.4

3 years ago

5.36.3

3 years ago

5.36.2

3 years ago

5.36.1

3 years ago

5.36.0

3 years ago

5.35.10

3 years ago

5.35.9

3 years ago

5.35.8

3 years ago

5.35.7

3 years ago

5.35.6

3 years ago

5.35.5

3 years ago

5.35.4

3 years ago

5.35.3

3 years ago

5.35.2

3 years ago

5.35.1

3 years ago

5.35.0

3 years ago

5.30.4

3 years ago

5.30.3

3 years ago

5.30.2

3 years ago

5.30.1

3 years ago

5.30.0

3 years ago

5.29.2

3 years ago

5.29.1

3 years ago

5.29.0

3 years ago

5.28.1

3 years ago

5.28.0

3 years ago

5.27.0

3 years ago

5.26.9

4 years ago

5.26.8

4 years ago

5.26.7

4 years ago

5.26.6

4 years ago

5.26.5

4 years ago

5.26.4

4 years ago

5.26.3

4 years ago

5.26.2

4 years ago

5.26.1

4 years ago

5.26.0

4 years ago

5.25.7

4 years ago

5.25.6

4 years ago

5.25.5

4 years ago

5.25.4

4 years ago

5.25.3

4 years ago

5.25.2

4 years ago

5.25.1

4 years ago

5.25.0

4 years ago

5.24.1

4 years ago

5.24.0

4 years ago

5.23.1

4 years ago

5.23.0

4 years ago

5.22.4

4 years ago

5.22.3

4 years ago

5.22.2

4 years ago

5.22.1

4 years ago

5.22.0

4 years ago

5.21.0

4 years ago

5.20.0

4 years ago

5.19.2

5 years ago

5.19.1

5 years ago

5.19.0

5 years ago

5.18.8

5 years ago

5.18.7

5 years ago

5.18.6

5 years ago

5.18.5

5 years ago

5.18.4

5 years ago

5.18.3

5 years ago

5.18.2

5 years ago

5.18.1

5 years ago

5.18.0

5 years ago

5.17.4

5 years ago

5.17.3

5 years ago

5.17.2

5 years ago

5.17.1

5 years ago

5.17.0

5 years ago

5.16.0

5 years ago

5.15.0

5 years ago

5.14.3

5 years ago

5.14.2

5 years ago

5.14.1

5 years ago

5.14.0

5 years ago

5.13.0

5 years ago

5.12.4

5 years ago

5.12.3

5 years ago

5.12.2

5 years ago

5.12.1

5 years ago

5.12.0

5 years ago

5.11.0

5 years ago

5.10.1

5 years ago

5.10.0

5 years ago

5.9.0

5 years ago

5.8.0

5 years ago

5.7.1

5 years ago

5.7.0

5 years ago

5.6.1

5 years ago

5.6.0

5 years ago

5.5.3

5 years ago

5.5.2

5 years ago

5.5.1

5 years ago

5.5.0

5 years ago

5.4.3

5 years ago

5.4.2

5 years ago

5.4.1

5 years ago

5.4.0

5 years ago

5.3.0

5 years ago

5.2.0

5 years ago

5.1.0

5 years ago

5.0.3

5 years ago

5.0.2

5 years ago

5.0.1

5 years ago

5.0.0

5 years ago

4.0.3

5 years ago

4.0.2

5 years ago

4.0.1

5 years ago

4.0.0

5 years ago

3.0.0

6 years ago

2.3.0

6 years ago

2.2.0

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago