README
ServiceNow Best Practices ESLint Plugin
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 name | Category | Description |
---|---|---|
gslog-source | Best Practices | Enforce use of gs.log calls with 2 arguments |
no-dotwalk-ref-id | Best Practices | Disallow dot-walking to the sys_id of reference field |
no-encoded-query-literal | Strict Mode | Enforce use of GlideRecord.addEncodedQuery calls without hardcoded literals |
no-encoded-query | Strict Mode | Disallow use of GlideRecord.addEncodedQuery calls |
no-gslog | Strict Mode | Disallow use of gs.log calls |
no-gsprint | Strict Mode | Disallow use of gs.print calls |
no-gssql | Strict Mode | Disallow use of gs.sql calls |
no-hardcoded-id | Best Practices | Disallow hardcoded Sys ID in Literals |
no-rowcount | Best Practices | Disallow use of GlideRecord.getRowCount calls |
no-synchronous-glideajax | Best Practices | Disallow 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 name | Reports as |
---|---|
gslog-source | warning |
no-dotwalk-ref-id | warning |
no-encoded-query-literal | warning |
no-gsprint | error |
no-gssql | error |
no-hardcoded-id | error |
no-rowcount | error |
no-synchronous-glideajax | warning |
strict Configuration
Rule name | Reports as |
---|---|
no-dotwalk-ref-id | error |
no-encoded-query | error |
no-gslog | error |
no-gsprint | error |
no-gssql | error |
no-hardcoded-id | error |
no-rowcount | error |
no-synchronous-glideajax | error |
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.
Global | Writable | References |
---|---|---|
global | false | Service Now global application scope |
current | false | currently edited GlideRecord |
previous | false | previous version of currently edited GlideRecord |
action | false | type of current action |
gs | false | global GlideSystem shortcut |
Class | false | global Service Now Class implementation |
AbstractAjaxProcessor | false | AJAX processor base class (Quebec) |
GSLog | false | GSLog (Quebec) |
GlideRecord | false | GlideRecord (Quebec) |
GlideAggregate | false | GlideAggregate (Quebec) |
GlideElement | false | GlideElement (Quebec) |
GlideDateTime | false | GlideDateTime (Quebec) |
GlideFilter | false | GlideFilter (Quebec) |
GlideSchedule | false | GlideSchedule (Quebec) |
GlideRecordUtil | false | GlideRecordUtil (Quebec) |
JSUtil | false | JSUtil (Quebec) |
ArrayUtil | false | ArrayUtil (Quebec) |
DurationCalculator | false | DurationCalculator (Quebec) |
j2js | false | j2js (Quebec) |
JSON | false | JSON (Quebec) |
JSONParser | false | JSONParser (Quebec) |
g_scratchpad | false | variable for GlideFormScratchpad (Quebec) |
snow-client Environment
Service Now environment to register "common" client global variables available within Service Now platform.
Global | Writable | References |
---|---|---|
g_menu | false | variable for GlideMenu |
g_item | false | variable for GlideMenu |
g_list | false | variable for GlideList2 |
g_form | false | variable for GlideForm (Quebec) |
g_scratchpad | false | variable for GlideFormScratchpad (Quebec) |
g_user | false | variable for GlideUser |
GlideAjax | false | client GlideAjax (Quebec) |
GlideDialogWindow | false | client GlideDialogWindow (Quebec) |
GlideList2 | false | client GlideList2 (Quebec) |
GlideMenu | false | client GlideMenu (Quebec) |
GlideUser | false | client GlideUser (Quebec) |
snow-sp Environment
Service Now environment to register "common" service portal global variables available within Service Now platform.
Global | Writable | References |
---|---|---|
data | true | server variable in Service Portal |
input | false | server variable in Service Portal |
angular | false | server variable in Service Portal |
$sp | false | server variable in Service Portal |
spUtil | false | server variable in Service Portal |
g_service_catalog | false | server variable in Service Portal |
g_list | false | server variable in Service Portal |
g_form | false | server variable in Service Portal |
GlideAjax | false | server variable in Service Portal |
GlideRecord | false | server variable in Service Portal |