0.0.2 • Published 4 years ago

@hrax/eslint-plugin-now-best-practices v0.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
4 years ago

ServiceNow Best Practices ESLint Plugin Test

Set of Service Now technical best practice rules to highlight common errors that occur during development of Service Now applications.

This plugin is not a replacement for tools such as QualityClouds or other PMD tools.

Installation

You'll first need to install ESLint:

$ npm i eslint --save-dev

Next, install @hrax/eslint-plugin-now-best-practices:

$ npm install @hrax/eslint-plugin-now-best-practices --save-dev

Usage

Add @hrax/now-best-practices to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:

{
    "plugins": [
        "@hrax/now-best-practices"
    ]
}

Rules

Add rule to the rules section of your .eslintrc configuration file.

{
    "rules": {
        "@hrax/now-best-practices/rule-name": 2
    }
}
Rule nameCategoryDescription
gslog-sourceBest PracticesEnforce use of gs.log calls with 2 arguments
no-dotwalk-ref-idBest PracticesDisallow dot-walking to the sys_id of reference field
no-encoded-query-literalStrict ModeEnforce use of GlideRecord.addEncodedQuery calls without hardcoded literals
no-encoded-queryStrict ModeDisallow use of GlideRecord.addEncodedQuery calls
no-gslogStrict ModeDisallow use of gs.log calls
no-gsprintStrict ModeDisallow use of gs.print calls
no-gssqlStrict ModeDisallow use of gs.sql calls
no-hardcoded-idBest PracticesDisallow hardcoded Sys ID in Literals
no-rowcountBest PracticesDisallow use of GlideRecord.getRowCount calls
no-synchronous-glideajaxBest PracticesDisallow use of of synchronous GlideAjax.getXMLWait and GlideAjax.getAnswer calls

Configurations

Add configuration to the extends section of your .eslintrc configuration file.

{
  "extends": ["plugin:@hrax/now-best-practices/configuration-name"]
}

recommended Configuration

Rule nameReports as
gslog-sourcewarning
no-dotwalk-ref-idwarning
no-encoded-query-literalwarning
no-gsprinterror
no-gssqlerror
no-hardcoded-iderror
no-rowcounterror
no-synchronous-glideajaxwarning

strict Configuration

Rule nameReports as
no-dotwalk-ref-iderror
no-encoded-queryerror
no-gslogerror
no-gsprinterror
no-gssqlerror
no-hardcoded-iderror
no-rowcounterror
no-synchronous-glideajaxerror

Environments

Add environment to the env section of your .eslintrc configuration file.

{
  "env": {
    "@hrax/now-best-practices/environment-name": true
  }
}

snow-server Environment

Service Now environment to register "common" server global variables available within Service Now platform.

GlobalWritableReferences
globalfalseService Now global application scope
currentfalsecurrently edited GlideRecord
previousfalseprevious version of currently edited GlideRecord
actionfalsetype of current action
gsfalseglobal GlideSystem shortcut
Classfalseglobal Service Now Class implementation
AbstractAjaxProcessorfalseAJAX processor base class (Quebec)
GSLogfalseGSLog (Quebec)
GlideRecordfalseGlideRecord (Quebec)
GlideAggregatefalseGlideAggregate (Quebec)
GlideElementfalseGlideElement (Quebec)
GlideDateTimefalseGlideDateTime (Quebec)
GlideFilterfalseGlideFilter (Quebec)
GlideSchedulefalseGlideSchedule (Quebec)
GlideRecordUtilfalseGlideRecordUtil (Quebec)
JSUtilfalseJSUtil (Quebec)
ArrayUtilfalseArrayUtil (Quebec)
DurationCalculatorfalseDurationCalculator (Quebec)
j2jsfalsej2js (Quebec)
JSONfalseJSON (Quebec)
JSONParserfalseJSONParser (Quebec)
g_scratchpadfalsevariable for GlideFormScratchpad (Quebec)

snow-client Environment

Service Now environment to register "common" client global variables available within Service Now platform.

GlobalWritableReferences
g_menufalsevariable for GlideMenu
g_itemfalsevariable for GlideMenu
g_listfalsevariable for GlideList2
g_formfalsevariable for GlideForm (Quebec)
g_scratchpadfalsevariable for GlideFormScratchpad (Quebec)
g_userfalsevariable for GlideUser
GlideAjaxfalseclient GlideAjax (Quebec)
GlideDialogWindowfalseclient GlideDialogWindow (Quebec)
GlideList2falseclient GlideList2 (Quebec)
GlideMenufalseclient GlideMenu (Quebec)
GlideUserfalseclient GlideUser (Quebec)

snow-sp Environment

Service Now environment to register "common" service portal global variables available within Service Now platform.

GlobalWritableReferences
datatrueserver variable in Service Portal
inputfalseserver variable in Service Portal
angularfalseserver variable in Service Portal
$spfalseserver variable in Service Portal
spUtilfalseserver variable in Service Portal
g_service_catalogfalseserver variable in Service Portal
g_listfalseserver variable in Service Portal
g_formfalseserver variable in Service Portal
GlideAjaxfalseserver variable in Service Portal
GlideRecordfalseserver variable in Service Portal