@admc.com/eslintplugin-sn-test 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/.eslintrc.json +82 -0
  2. package/.gitattributes +117 -0
  3. package/LICENSE +176 -0
  4. package/README.md +17 -0
  5. package/badScripts/global/invalid_table/invalidTable.js +1 -0
  6. package/badScripts/global/sys_script/initToUndefined.js +2 -0
  7. package/badScripts/global/sys_script/sane.js +1 -0
  8. package/badScripts/global/sys_script/scopedLog.js +1 -0
  9. package/badScripts/global/sys_script/unusedVar.js +1 -0
  10. package/badScripts/global/sys_script_include/createOtherFn.js +3 -0
  11. package/badScripts/invalid/sys_script/invalidAltscope.js +1 -0
  12. package/badScripts/invalid_table/invalidTable.js +1 -0
  13. package/badScripts/iso/sys_script_client/document.js +1 -0
  14. package/badScripts/iso/sys_script_client/gs.js +1 -0
  15. package/badScripts/iso/sys_script_client/jQuery.js +1 -0
  16. package/badScripts/iso/sys_script_client/window.js +1 -0
  17. package/badScripts/noniso/sys_script_client/gs.js +1 -0
  18. package/badScripts/scoped/sys_script/globalLog.js +1 -0
  19. package/badScripts/scoped/sys_script/globalSiObj.js +1 -0
  20. package/badScripts/scoped/sys_script/let.js +2 -0
  21. package/eslintrc.json +39 -0
  22. package/functions.bash +61 -0
  23. package/goodScripts/ecc_agent_script/good.js +6 -0
  24. package/goodScripts/global/sys_script/good.js +12 -0
  25. package/goodScripts/global/sys_script/sane.js +1 -0
  26. package/goodScripts/global/sys_script_include/createOtherClass.js +11 -0
  27. package/goodScripts/global/sys_script_include/createSameFn.js +3 -0
  28. package/goodScripts/iso/sys_script_client/good.js +10 -0
  29. package/goodScripts/noniso/sys_script_client/good.js +10 -0
  30. package/goodScripts/scoped/sys_script/good.js +11 -0
  31. package/masterTest.js +30 -0
  32. package/package.json +31 -0
  33. package/populateTest.bash +80 -0
package/.eslintrc.json ADDED
@@ -0,0 +1,82 @@
1
+ // This is for checking js files in the eslintplugin-sn-test implementation itself.
2
+ // Don't use this for checking ServiceNow scriptlets.
3
+ {
4
+ "env": { "es2022": true, "node": true },
5
+ "extends": "eslint:recommended",
6
+ "parserOptions": { "ecmaVersion": "latest" },
7
+ "ignorePatterns": ["goodScripts/**", "badScripts/**", "test/**"],
8
+ "rules": {
9
+ "camelcase": "warn",
10
+ "eqeqeq": "error",
11
+ "no-var": "error",
12
+ "prefer-const": "error",
13
+ "semi": "error",
14
+ "no-unreachable-loop": "error",
15
+ "no-use-before-define": ["error", { "functions": false, "classes": false }],
16
+ "no-extra-parens": "warn",
17
+
18
+ // Node-like-specific
19
+ "no-duplicate-imports": "error",
20
+
21
+ "operator-assignment": "error",
22
+ "no-useless-return": "error",
23
+ "prefer-regex-literals": ["error", { "disallowRedundantWrapping": true}],
24
+ "no-useless-concat": "error",
25
+ "no-useless-computed-key": "error",
26
+ "no-useless-call": "error",
27
+ "no-unused-expressions": "error",
28
+ "no-undef-init": "error",
29
+ "no-proto": "error",
30
+ "no-new-wrappers": "error",
31
+ "no-new-object": "error",
32
+ "no-negated-condition": "error",
33
+ "no-loop-func": "error",
34
+ "no-lonely-if": "error",
35
+ "no-lone-blocks": "error",
36
+ "no-implied-eval": "warn",
37
+ "no-eval": "warn",
38
+ "no-extra-label": "error",
39
+ "no-extra-bind": "error",
40
+ "no-else-return": "error",
41
+ "no-array-constructor": "warn",
42
+ "new-cap": "error",
43
+ "max-depth": "warn",
44
+ "dot-notation": "error",
45
+ "consistent-return": "error",
46
+ "class-methods-use-this": "error",
47
+ "block-scoped-var": "error",
48
+ "no-template-curly-in-string": "warn",
49
+ "no-self-compare": "error",
50
+ "no-constructor-return": "error",
51
+ "no-constant-binary-expression": "error",
52
+ "array-callback-return": ["error", { "checkForEach": true }],
53
+
54
+ // Post-ES6
55
+ "strict": ["error", "safe"],
56
+ "prefer-exponentiation-operator": "error",
57
+ "prefer-arrow-callback": "error",
58
+ "object-shorthand": "error",
59
+ "no-useless-rename": "error",
60
+ "no-useless-constructor": "error",
61
+ "prefer-template": "error",
62
+ "no-iterator": "error",
63
+ "require-atomic-updates": "error",
64
+ "no-unused-private-class-members": "error",
65
+ "no-promise-executor-return": "error",
66
+
67
+ // formatting
68
+ "comma-spacing": "warn",
69
+ "dot-location": "warn",
70
+ "eol-last": "error",
71
+ "func-call-spacing": "error",
72
+ "keyword-spacing": "error",
73
+ "linebreak-style": "error",
74
+ "max-len": ["error", { "code": 100, "ignoreUrls": true }],
75
+ "no-multi-spaces": ["error", { "ignoreEOLComments": true }],
76
+ "no-tabs": "error",
77
+ "no-trailing-spaces": "error",
78
+ "no-whitespace-before-property": "error",
79
+ "padded-blocks": ["error", "never"],
80
+ "rest-spread-spacing": "error"
81
+ }
82
+ }
package/.gitattributes ADDED
@@ -0,0 +1,117 @@
1
+ * text=auto
2
+
3
+ *.bash eol=lf
4
+ *.sh eol=lf
5
+ *.ksh eol=lf
6
+ *.csh eol=lf
7
+ *.pem eol=lf
8
+ *.cmd eol=crlf
9
+ *.bat eol=crlf
10
+ *.BAT eol=crlf
11
+ *.CMD eol=crlf
12
+ *.dsp eol=crlf
13
+ *.sln eol=crlf
14
+ *.vcproj eol=crlf
15
+ *.reg eol=crlf
16
+
17
+ *.PNG -text
18
+ *.png -text
19
+ *.jpg -text
20
+ *.gif -text
21
+ *.bmp -text
22
+ *.ico -text
23
+ *.pdf -text
24
+ *.zip -text
25
+ *.tar -text
26
+ *.rar -text
27
+ *.jar -text
28
+ *.so -text
29
+ *.3DS -text
30
+ *.3ds -text
31
+ *.class -text
32
+ *.tga -text
33
+ *.xcf -text
34
+ *.xcf.gz -text
35
+ *.xcf.bz2 -text
36
+ *.ogg -text
37
+ *.mp3 -text
38
+ *.wav -text
39
+ *.dds -text
40
+ *.dll -text
41
+ *.dylib -text
42
+ *.jbf -text
43
+ *.jme -text
44
+ *.bin -text
45
+ *.ser -text
46
+ *.jnilib -text
47
+ *.ms3d -text
48
+ *.raw -text
49
+
50
+ *.txt text
51
+ *.creole text
52
+ *.list text
53
+ *.text text
54
+ *.tpl text
55
+ *.dsv lf
56
+ *.html lf
57
+ *.ent text
58
+ *.xhtml text
59
+ *.dtd text
60
+ *.java text
61
+ *.groovy text
62
+ *.gradle text
63
+ *.jsp text
64
+ *.ase text
65
+ *.cfg text
66
+ .cvsignore text
67
+ .gitignore text
68
+ .gitattriutes text
69
+ *.css text
70
+ *.dae text
71
+ *.jnlp text
72
+ *.mtl text
73
+ *.obj text
74
+ *.material text
75
+ *.php text
76
+ *.properties text
77
+ *.vert text
78
+ *.frag text
79
+ *.x3d text
80
+ *.xml text
81
+ *.svg text
82
+ *.ac text
83
+ *.am text
84
+ *.def text
85
+ *.m4 text
86
+ *.rc text
87
+ *.wxs text
88
+ Makefile text
89
+ makefile text
90
+ *.mf text
91
+ *.MF text
92
+ *.mak text
93
+ *.c text
94
+ *.cpp text
95
+ *.pl text
96
+ *.pm text
97
+ *.csv text
98
+ *.shtml text
99
+ *.htm text
100
+ *.js lf
101
+ *.jsm lf
102
+ *.sql text
103
+ *.isq text
104
+ *.nsq text
105
+ *.bsh text
106
+ *.ini text
107
+ *.lst text
108
+ *.py text
109
+ *.style text
110
+ *.xsd text
111
+ *.rng text
112
+ *.xsl text
113
+ *.xslt text
114
+ *.dtd text
115
+ *.json lf
116
+ *.md text
117
+ LICENSE text
package/LICENSE ADDED
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ Copyright 2022 Axis Data Management Corp.
package/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # Description
2
+ External tests for ESLint plugin @admc.com/eslint-plugin-sn
3
+
4
+ # Installation
5
+ ```
6
+ npm i @admc.com/sn
7
+ ```
8
+
9
+ # Setup
10
+ ```
11
+ npm run setup
12
+ ```
13
+
14
+ # Execute tests
15
+ ```
16
+ npm test
17
+ ```
@@ -0,0 +1 @@
1
+ if ([].forEach === undefined) throw new Error("Should never get this");
@@ -0,0 +1,2 @@
1
+ var unusedVar = undefined;
2
+ if (!unusedVar) gs.log("notset", "2nd");
@@ -0,0 +1 @@
1
+ console.log("Hello world", "sane.js");
@@ -0,0 +1 @@
1
+ gs.info("message");
@@ -0,0 +1 @@
1
+ var unusedVar = 3;
@@ -0,0 +1,3 @@
1
+ function aFunction() {
2
+ return 7;
3
+ }
@@ -0,0 +1 @@
1
+ if ([].forEach === undefined) throw new Error("Should never get this");
@@ -0,0 +1 @@
1
+ if ([].forEach === undefined) throw new Error("Should never get this");
@@ -0,0 +1 @@
1
+ console.info(document.URL);
@@ -0,0 +1 @@
1
+ console.info(gs.getUserName());
@@ -0,0 +1 @@
1
+ console.info( jQuery("body").length);
@@ -0,0 +1 @@
1
+ console.info(window.name);
@@ -0,0 +1 @@
1
+ console.info(gs.getUserName());
@@ -0,0 +1 @@
1
+ gs.log("msg", "2nd");
@@ -0,0 +1 @@
1
+ gs.info(SNC.CMDBUtil.getTables0("sys_db_object"));
@@ -0,0 +1,2 @@
1
+ let x = 3;
2
+ gs.log(3, 'src');
package/eslintrc.json ADDED
@@ -0,0 +1,39 @@
1
+ /* N.b. this file is used by 'snLint'.
2
+ * It would not be honored by 'eslint' directly unless you use the -c switch.
3
+ * Override settings must specify source files with path format
4
+ * 'TABLENAME/BASENAME.js' or 'TABLENAME/ALTSCOPE/BASENAME.js'.
5
+ * Example: "sys_script/global/sane.js" */
6
+ {
7
+ "root": true,
8
+ "plugins": ["@admc.com/sn"],
9
+ "extends": ["plugin:@admc.com/sn/servicenow"],
10
+
11
+ // Following are overrides which escalate warns to errors.
12
+ // Tests only work if the leve is error because we check only snLint/eslint return value,
13
+ // not the stdout or stderr.
14
+ "rules": {
15
+ "no-implied-eval": "error",
16
+ "no-eval": "error",
17
+ "no-array-constructor": "error",
18
+ "max-depth": "error",
19
+ "dot-notation": "error",
20
+ "camelcase": "error",
21
+ "no-template-curly-in-string": "error",
22
+ "eqeqeq": "error",
23
+ "semi": "error",
24
+ "no-extra-parens": "error"
25
+ },
26
+ "overrides": [
27
+ {
28
+ "files": ["**/@(sys|catalog|expert)_script_client/@(noniso|iso)/*.js"],
29
+ "rules": {
30
+ "strict": ["error", "safe"],
31
+ "prefer-arrow-callback": "error",
32
+ "object-shorthand": "error",
33
+ "no-useless-rename": "error",
34
+ "no-var": "error",
35
+ "prefer-template": "error"
36
+ }
37
+ }
38
+ ]
39
+ }
package/functions.bash ADDED
@@ -0,0 +1,61 @@
1
+ # Useful shell functions
2
+
3
+ function rchead() {
4
+ local TARGET_FILE=eslintrc.json
5
+ local SYNTAX_MSG='SYNTAX: rchead n # where n is a positive integer'
6
+ [ -f "$TARGET_FILE" ] || {
7
+ echo "rchead file '$TARGET_FILE' not present or not a file" 1>&2
8
+ return 3
9
+ }
10
+ [ -r "$TARGET_FILE" ] || {
11
+ echo "rchead file '$TARGET_FILE' not readable" 1>&2
12
+ return 3
13
+ }
14
+ [ $# -ne 1 ] && {
15
+ echo "$SYNTAX_MSG" 1>&2
16
+ return 2
17
+ }
18
+ count="$1"; shift
19
+ case "$count" in *[^0-9]*)
20
+ echo -e "Invalid positive integer: $count\n$SYNTAXMSG"
21
+ return 2;;
22
+ esac
23
+ case "$count" in *[1-9]*);; *)
24
+ echo -e "Zero integer is not positive: $count\n$SYNTAXMSG"
25
+ return 2;;
26
+ esac
27
+ head -c $count "$TARGET_FILE"
28
+ local retVal=$?
29
+ echo
30
+ [ $? -eq 0 ] || return $retVal
31
+ }
32
+
33
+ function rcheaddot() {
34
+ local TARGET_FILE=.eslintrc.json
35
+ local SYNTAX_MSG='SYNTAX: rchead n # where n is a positive integer'
36
+ [ -f "$TARGET_FILE" ] || {
37
+ echo "rchead file '$TARGET_FILE' not present or not a file" 1>&2
38
+ return 3
39
+ }
40
+ [ -r "$TARGET_FILE" ] || {
41
+ echo "rchead file '$TARGET_FILE' not readable" 1>&2
42
+ return 3
43
+ }
44
+ [ $# -ne 1 ] && {
45
+ echo "$SYNTAX_MSG" 1>&2
46
+ return 2
47
+ }
48
+ count="$1"; shift
49
+ case "$count" in *[^0-9]*)
50
+ echo -e "Invalid positive integer: $count\n$SYNTAXMSG"
51
+ return 2;;
52
+ esac
53
+ case "$count" in *[1-9]*);; *)
54
+ echo -e "Zero integer is not positive: $count\n$SYNTAXMSG"
55
+ return 2;;
56
+ esac
57
+ head -c $count "$TARGET_FILE"
58
+ local retVal=$?
59
+ echo
60
+ [ $? -eq 0 ] || return $retVal
61
+ }
@@ -0,0 +1,6 @@
1
+ var TstCls = Class.create();
2
+ TstCls.prototype.initialize = function(o) {
3
+ this.o = o;
4
+ this.p = String(Packages.java.lang.System.getProperty(o));
5
+ };
6
+ ctx.setAttribute("A", "aye");
@@ -0,0 +1,12 @@
1
+ // Test availability of global vars from the different component lists:
2
+ gs.log("a message", "a source"); // coreServerObjects.txt
3
+ gs.log(SNC.CMDBUtil.getTables0("sys_db_object"), "src"); // directly in exports.js
4
+ // eslint-disable-next-line camelcase
5
+ gs.log(Object.keys(new sn_codesearch.CodeSearch()).length, "src"); // SIScopes
6
+
7
+ var varsAreAllowed = "a val";
8
+ gs.log(varsAreAllowed, "2nd");
9
+
10
+ const con = "a val";
11
+ con += "addition"; // Can't test for const changes
12
+ gs.log(con, "2nd");
@@ -0,0 +1 @@
1
+ gs.log("Hello world", "sane.js");
@@ -0,0 +1,11 @@
1
+ // This passes test because we assign to the new class.
2
+ // This is how SI classes are generally instantiated on SN, because this
3
+ // is how the auto-generated code templates do it.
4
+ var OtherAjaxProcessor = Class.create();
5
+
6
+ OtherAjaxProcessor.prototype = Object.extendsObject(AbstractAjaxProcessor, {
7
+ type: "OtherAjaxProcessor",
8
+ _getStringParam: function() {
9
+ return undefined;
10
+ },
11
+ });
@@ -0,0 +1,3 @@
1
+ function createSameFn() {
2
+ return 7;
3
+ }
@@ -0,0 +1,10 @@
1
+ let v = "four";
2
+ const dblr = v=>{'use strict'; return v+v;};
3
+
4
+ function onLoad() {
5
+ 'use strict';
6
+ console.info("I am here in onLoad");
7
+ }
8
+
9
+ v = dblr(v);
10
+ console.info(v, new URL("https://cnn.com/"));
@@ -0,0 +1,10 @@
1
+ let v = "four";
2
+ const dblr = v=>{'use strict'; return v+v;};
3
+
4
+ function onLoad() {
5
+ "use strict";
6
+ console.info("Here in onLoad");
7
+ }
8
+
9
+ v = dblr(v);
10
+ console.info(window.name, v, jQuery("body").length, document.URL);
@@ -0,0 +1,11 @@
1
+ // Test availability of scoped vars from the different component lists:
2
+ gs.info("a message"); // coreServerObjects.txt
3
+ // eslint-disable-next-line camelcase
4
+ gs.info(Object.keys(new sn_codesearch.CodeSearch()).length); // SIScopes
5
+
6
+ var varsAreAllowed = "a val";
7
+ gs.info(varsAreAllowed);
8
+
9
+ const con = "a val";
10
+ con += "addition"; // Can't test for const changes
11
+ gs.info(con);
package/masterTest.js ADDED
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ /* global it */
3
+ if (!__filename.startsWith(process.cwd() + "/")) // eslint-disable-line prefer-template
4
+ throw new Error("You must execute these tests from the package base directory");
5
+ const relTestPath = __filename.substring(process.cwd().length + 1);
6
+ const path = require("path");
7
+ const fs = require("fs");
8
+ const ex = /^test[/](good|bad)[/](?:(\w+)[/])?(\w+[/]\w+)-test[.]js$/.exec(relTestPath);
9
+ if (!ex) throw new Error(`Bad test file path: ${relTestPath}`);
10
+ const shouldSucceed = ex[1] === "good";
11
+ const altscope = ex[2];
12
+ const tableBase = ex[3];
13
+ // eslint-disable-next-line no-extra-parens, prefer-template
14
+ const scriptPath = path.join(`${ex[1]}Scripts`, `${altscope?(altscope+"/"):""}${tableBase}.js`);
15
+ if (!fs.existsSync(scriptPath)) throw new Error(`Script file missing: ${scriptPath}`);
16
+ if (!fs.statSync(scriptPath).isFile()) throw new Error(`Script is not a file: ${scriptPath}`);
17
+ const params = [ "node_modules/.bin/snLint", scriptPath ];
18
+ if (altscope) params.splice(1, 0, "-a", altscope);
19
+ if (process.env.DEBUG) {
20
+ params.splice(1, 0, "-d");
21
+ console.debug("Lint params:", params);
22
+ }
23
+ const childProcess = require("child_process").
24
+ spawnSync(process.execPath, params, { stdio: "inherit" });
25
+
26
+ it(altscope ? `${tableBase} | ${altscope}` : tableBase, () => {
27
+ if (shouldSucceed && childProcess.status !== 0
28
+ || !shouldSucceed && childProcess.status === 0)
29
+ throw new Error(`Failed with code ${childProcess.status}`);
30
+ });
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@admc.com/eslintplugin-sn-test",
3
+ "version": "1.0.0",
4
+ "description": "External tests for ESLint plugin @admc.com/eslint-plugin-sn",
5
+ "scripts": {
6
+ "test": "mocha --recursive",
7
+ "test1": "DEBUG=true mocha",
8
+ "snLint": "snLint -d",
9
+ "setup": "snLint -g . && populateTest.bash -v",
10
+ "lint": "eslint"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/unsaved/eslint-plugin-sn.git"
15
+ },
16
+ "keywords": [
17
+ "eslint",
18
+ "eslintplugin",
19
+ "servicenow"
20
+ ],
21
+ "author": "Blaine Simpson <blaine.simpson@admc.com>",
22
+ "license": "Apache-2.0",
23
+ "bugs": {
24
+ "url": "https://github.com/unsaved/eslint-plugin-sn/issues"
25
+ },
26
+ "homepage": "https://github.com/unsaved/eslint-plugin-sn#readme",
27
+ "dependencies": {
28
+ "@admc.com/eslint-plugin-sn": "^1.0.1",
29
+ "mocha": "^10.0.0"
30
+ }
31
+ }
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env bash
2
+ PROGNAME="${0##*/}"
3
+
4
+ # This script creates hard node copies of 'masterTest.js' for each script to test.
5
+ # Can't use sym-links because Node's __filepath resolves to the target file instead
6
+ # of the link (weird).
7
+
8
+ # $Id$
9
+
10
+ set +u
11
+ shopt -s xpg_echo
12
+ unset FORCE V_SWITCH REPLACE_MODE
13
+
14
+ SYNTAX_MSG="$PROGNAME [-h] [-r] [-v]
15
+ -f: Force replacement of existing test scripts (if any).
16
+ By defaults leaves existing ones as-is.
17
+ -h: Display this Help text
18
+ -r: Regenerate the test tree completely, wiping what was there previously
19
+ -v: Verbose"
20
+
21
+ # : at beginning for silent mode. All other :s represent str arg for prev. opt.
22
+ # 'option' is a placeholder variable here. Can use anything.
23
+ while getopts ':fhrv' option; do
24
+ case "$option" in
25
+ f) FORCE=true;;
26
+ r) REPLACE_MODE=true;;
27
+ v) V_SWITCH=-v;;
28
+ h) echo "$SYNTAX_MSG"; exit 0;;
29
+ '?') echo "Invalid switch: -$OPTARG\n$SYNTAX_MSG" 1>&2; exit 3;;
30
+ ':') echo "Switch must be followed by space and a string: -$OPTARG\n$SYNTAS_MSG" 1>&2
31
+ exit 3;;
32
+ *) echo "Internal error. Unexpected switch -$option" 1>&2; exit 3;;
33
+ esac
34
+ done
35
+
36
+ shift $(($OPTIND - 1))
37
+
38
+ [ $# -ne 0 ] && {
39
+ echo "SYNTAX_MSG" 1>&2
40
+ exit 3
41
+ }
42
+
43
+ Abort() {
44
+ echo "Aborting $PROGNAME: $*" 1>&2
45
+ exit 1
46
+ }
47
+
48
+ [ -f masterTest.js ] || Abort "Master test script 'masterTest.js' is missing"
49
+ [ -n "$TMPDIR" ] || TMPDIR=/tmp
50
+ TMPFILE="$TMPDIR/${PROGNAME#.*}.$$"
51
+ trap 'rm -f "$TMPFILE"' EXIT
52
+ [ -d goodScripts ] || Abort "Directory 'goodScripts' is missing"
53
+ [ -d badScripts ] || Abort "Directory 'badScripts' is missing"
54
+ find goodScripts badScripts -name '*.js' > "$TMPFILE" ||
55
+ Abort 'find command failed'
56
+ [ -n "$REPLACE_MODE" ] && rm -rf test/good test/bad
57
+ while read SCRIPT_PATH; do
58
+ GB=
59
+ case "$SCRIPT_PATH" in
60
+ badScripts/*) GB=bad;;
61
+ goodScripts/*) GB=good;;
62
+ *) Abort "Unexpected SCRIPT_PATH prefix: $SCRIPT_PATH";;
63
+ esac
64
+ REBASED="test/$GB/${SCRIPT_PATH#*Scripts/}"
65
+ TEST_PATH="${REBASED%.js}-test.js"
66
+ [ -e "$TEST_PATH" ] && {
67
+ [ -f "$TEST_PATH" ] || Abort "Existing filesystem node not a file: $TEST_PATH"
68
+ [ -n "$FORCE" ] || {
69
+ [ -n "$V_SWITCH" ] && echo "Retaining existing test script '$TEST_PATH'"
70
+ continue
71
+ }
72
+ rm $VSWITCH -f "$TEST_PATH"
73
+ }
74
+ [ -d "${TEST_PATH%/*}" ] || {
75
+ mkdir $V_SWITCH -p "${TEST_PATH%/*}" ||
76
+ Abort "Failed to create directory '${TEST_PATH%/*}'"
77
+ }
78
+ ln $V_SWITCH masterTest.js "$TEST_PATH" ||
79
+ Abort "Failed to create hard link '$TEST_PATH'"
80
+ done < "$TMPFILE"