Coder Social home page Coder Social logo

joernberkefeld / eslint-config-ssjs Goto Github PK

View Code? Open in Web Editor NEW
17.0 4.0 1.0 666 KB

preset for Salesforce Marketing Cloud's Server-Side JavaScript

License: MIT License

JavaScript 100.00%
ssjs sfmc marketing-cloud eslint eslint-config eslint-config-ssjs exacttarget salesforce

eslint-config-ssjs's Introduction

eslint-config-ssjs

Preset for Salesforce Marketing Cloud's Server-Side JavaScript.

ESLint shareable config

NPM

Features

  • rules limited to *.ssjs files
  • all SSJS classes/methods offered by SFMC are defined as unchangable globals
  • ecma script 3 pre-defined
  • quirks of SSJS handled via custom rules
  • based on eslint recommended rules with as little changes as possible

Installation

npm install --save-dev eslint eslint-config-ssjs

Usage

Once the eslint-config-ssjs package is installed, you can use it by specifying ssjs in the extends section of your ESLint configuration.

Important: Make sure that your SSJS files end on *.ssjs and not on *.js.

{
  "extends": "ssjs",
  "rules": {
    // your other rules
  }
}

It's good practice to use eslint:recommended ruleset in your project to support front end scripts.

To use SSJS in conjunction with ESLint's recommended rule set, extend with both, making sure to list ssjs last. We do recommend to also use this together with eslint-config-prettier and eslint-plugin-prettier

{
  "extends": ["eslint:recommended", "prettier", "ssjs"],
  "plugins": ["prettier"],
  "rules": {
    // your other rules that don't conflict with the SSJS config
  },
  "overrides": [
    {
      // your target JavaScript version and conflicting rules should only be
      // set as override, as they would otherwise supersede the SSJS config
      "files": ["*.js"],
      "parserOptions": {
        "ecmaVersion": 6
      },
      "rules": {
        // the following rules should only be set here in the 'overrides' section
        "prettier/prettier": "warn",
        // note that the following is not setting proper values to the rules as
        // that is up to your style guide. The empty "" are merely placeholders
        "comma-dangle": "",
        "new-cap": "",
        "no-console": "",
        "no-extend-native": "",
        "no-new": "",
        "no-prototype-builtins": "",
        "no-throw-literal": "",
        "no-use-before-define": "",
        "no-var": ""
      }
    }
  ]

}

Using Prettier with SSJS

Starting with version 2.x of prettier, the plugin automatically has "trailingComma" set to "es5". That's a problem because SSJS actually does not support this.

Also, SFMC tends to remove all tabs when you save queries, scripts, code snippets, emails and cloud pages. We hence strongly recommend to set useTabs to false and define tabWidth according to your liking (2 or 4 are typical values).

Add the following to your .prettierrc file to ensure the above concerns are adressed:

{
    "useTabs": false,
    "tabWidth": 4,
    "singleQuote": true,
    "overrides": [
        {
            "files": "*.ssjs",
            "options": {
                "trailingComma": "none"
            }
        }
    ]
}

Using the .ssjs extension in VSCode

Make sure you associate *.ssjs with JavaScript in your IDE. That should automatically enable linting via ESLint.

License

MIT licensed

eslint-config-ssjs's People

Contributors

dependabot[bot] avatar joernberkefeld avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.