es-check 8.0.1 → 8.0.2
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.
- package/README.md +3 -4
- package/detectFeatures.js +5 -1
- package/index.js +9 -8
- package/package.json +11 -11
- package/utils.js +42 -24
package/README.md
CHANGED
|
@@ -177,15 +177,14 @@ es-check es6 './dist/**/*.js' --checkFeatures
|
|
|
177
177
|
Options:
|
|
178
178
|
-V, --version output the version number
|
|
179
179
|
--module use ES modules
|
|
180
|
-
--
|
|
180
|
+
--allowHashBang if the code starts with #! treat it as a comment (default: false)
|
|
181
181
|
--files <files> a glob of files to to test the EcmaScript version against (alias for [files...])
|
|
182
182
|
--not <files> folder or file names to skip
|
|
183
|
-
--
|
|
183
|
+
--noColor disable use of colors in output (default: false)
|
|
184
184
|
-v, --verbose verbose mode: will also output debug messages (default: false)
|
|
185
185
|
--quiet quiet mode: only displays warn and error messages (default: false)
|
|
186
186
|
--looseGlobMatching doesn't fail if no files are found in some globs/files (default: false)
|
|
187
|
-
--silent silent mode: does not output anything, giving no indication of success or
|
|
188
|
-
failure other than the exit code (default: false)
|
|
187
|
+
--silent silent mode: does not output anything, giving no indication of success or failure other than the exit code (default: false)
|
|
189
188
|
--checkFeatures check for actual ES version specific features (default: false)
|
|
190
189
|
-h, --help display help for command
|
|
191
190
|
|
package/detectFeatures.js
CHANGED
|
@@ -68,10 +68,14 @@ const detectFeatures = (code, ecmaVersion, sourceType) => {
|
|
|
68
68
|
* @note Fail if any unsupported features were used.
|
|
69
69
|
*/
|
|
70
70
|
if (unsupportedFeatures.length > 0) {
|
|
71
|
-
|
|
71
|
+
const error = new Error(
|
|
72
72
|
`Unsupported features detected: ${unsupportedFeatures.join(', ')}. ` +
|
|
73
73
|
`These require a higher ES version than ${ecmaVersion}.`
|
|
74
74
|
);
|
|
75
|
+
error.type = 'ES-Check';
|
|
76
|
+
error.features = unsupportedFeatures;
|
|
77
|
+
error.ecmaVersion = ecmaVersion;
|
|
78
|
+
throw error;
|
|
75
79
|
}
|
|
76
80
|
|
|
77
81
|
return {
|
package/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
'use strict'
|
|
4
4
|
|
|
5
|
-
const { program } = require('commander')
|
|
5
|
+
const { program, Option } = require('commander')
|
|
6
6
|
const acorn = require('acorn')
|
|
7
7
|
const glob = require('fast-glob')
|
|
8
8
|
const fs = require('fs')
|
|
@@ -10,6 +10,7 @@ const path = require('path')
|
|
|
10
10
|
const supportsColor = require('supports-color')
|
|
11
11
|
const winston = require('winston')
|
|
12
12
|
const detectFeatures = require('./detectFeatures')
|
|
13
|
+
const { formatError } = require('./utils')
|
|
13
14
|
const pkg = require('./package.json')
|
|
14
15
|
|
|
15
16
|
/**
|
|
@@ -29,10 +30,12 @@ program
|
|
|
29
30
|
)
|
|
30
31
|
.argument('[files...]', 'a glob of files to to test the EcmaScript version against')
|
|
31
32
|
.option('--module', 'use ES modules')
|
|
32
|
-
.
|
|
33
|
+
.addOption(new Option('--allow-hash-bang', 'if the code starts with #! treat it as a comment').default(false).hideHelp())
|
|
34
|
+
.option('--allowHashBang', 'if the code starts with #! treat it as a comment', false)
|
|
33
35
|
.option('--files <files>', 'a glob of files to to test the EcmaScript version against (alias for [files...])')
|
|
34
36
|
.option('--not <files>', 'folder or file names to skip')
|
|
35
|
-
.
|
|
37
|
+
.addOption(new Option('--no-color', 'disable use of colors in output').default(false).hideHelp())
|
|
38
|
+
.option('--noColor', 'disable use of colors in output', false)
|
|
36
39
|
.option('-v, --verbose', 'verbose mode: will also output debug messages', false)
|
|
37
40
|
.option('--quiet', 'quiet mode: only displays warn and error messages', false)
|
|
38
41
|
.option('--looseGlobMatching', 'doesn\'t fail if no files are found in some globs/files', false)
|
|
@@ -224,13 +227,11 @@ program
|
|
|
224
227
|
logger.debug(`Features found in ${file}: ${stringifiedFeatures}`);
|
|
225
228
|
const isSupported = unsupportedFeatures.length === 0;
|
|
226
229
|
if (!isSupported) {
|
|
227
|
-
|
|
228
|
-
`ES-Check: The file "${file}" uses these unsupported features: ${unsupportedFeatures.join(', ')}
|
|
229
|
-
but your target is ES${ecmaVersion}.`
|
|
230
|
-
);
|
|
230
|
+
const error = new Error(`Unsupported features used: ${unsupportedFeatures.join(', ')} but your target is ES${ecmaVersion}.`);
|
|
231
231
|
errArray.push({
|
|
232
|
-
err:
|
|
232
|
+
err: error,
|
|
233
233
|
file,
|
|
234
|
+
stack: error.stack
|
|
234
235
|
});
|
|
235
236
|
}
|
|
236
237
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "es-check",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.2",
|
|
4
4
|
"description": "Checks the ECMAScript version of .js glob against a specified version of ECMAScript with a shell command",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"license": "MIT",
|
|
@@ -41,30 +41,30 @@
|
|
|
41
41
|
},
|
|
42
42
|
"homepage": "https://github.com/yowainwright/es-check#readme",
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@commitlint/cli": "19.
|
|
45
|
-
"@commitlint/config-conventional": "19.
|
|
44
|
+
"@commitlint/cli": "19.7.1",
|
|
45
|
+
"@commitlint/config-conventional": "19.7.1",
|
|
46
46
|
"@commitlint/format": "^19.3.0",
|
|
47
|
-
"@commitlint/prompt": "19.
|
|
47
|
+
"@commitlint/prompt": "19.7.1",
|
|
48
48
|
"assert": "^2.1.0",
|
|
49
49
|
"codecov": "^3.8.3",
|
|
50
50
|
"codependence": "^0.3.1",
|
|
51
51
|
"commitizen": "4.3.1",
|
|
52
52
|
"conventional-changelog-cli": "^5.0.0",
|
|
53
|
-
"eslint": "9.
|
|
54
|
-
"eslint-config-prettier": "
|
|
53
|
+
"eslint": "9.21.0",
|
|
54
|
+
"eslint-config-prettier": "10.0.2",
|
|
55
55
|
"husky": "9.1.7",
|
|
56
56
|
"is-ci": "^3.0.1",
|
|
57
|
-
"mocha": "11.0
|
|
57
|
+
"mocha": "11.1.0",
|
|
58
58
|
"nyc": "^17.1.0",
|
|
59
59
|
"path-exists-cli": "^2.0.0",
|
|
60
|
-
"prettier": "3.
|
|
61
|
-
"release-it": "
|
|
60
|
+
"prettier": "3.5.3",
|
|
61
|
+
"release-it": "18.1.2"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
64
|
"acorn": "8.14.0",
|
|
65
65
|
"acorn-walk": "^8.3.4",
|
|
66
|
-
"commander": "
|
|
67
|
-
"fast-glob": "^3.3.
|
|
66
|
+
"commander": "13.1.0",
|
|
67
|
+
"fast-glob": "^3.3.3",
|
|
68
68
|
"supports-color": "8.1.1",
|
|
69
69
|
"winston": "3.17.0"
|
|
70
70
|
},
|
package/utils.js
CHANGED
|
@@ -38,37 +38,40 @@ const checkDefault = () => {
|
|
|
38
38
|
* - objectMethod => object: 'Object', property: 'fromEntries', etc.
|
|
39
39
|
*/
|
|
40
40
|
const checkCallExpression = (node, astInfo) => {
|
|
41
|
-
// Must be `CallExpression`
|
|
42
41
|
if (node.type !== 'CallExpression') return false;
|
|
43
|
-
|
|
44
|
-
// We might check if node.callee is a MemberExpression, e.g. array.includes(...)
|
|
45
|
-
// or if node.callee is an Identifier, e.g. Symbol(...).
|
|
46
42
|
if (node.callee.type === 'MemberExpression') {
|
|
47
43
|
const { object, property } = astInfo;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
44
|
+
|
|
45
|
+
if (object || property) {
|
|
46
|
+
|
|
47
|
+
if (object) {
|
|
48
|
+
if (
|
|
49
|
+
!node.callee.object ||
|
|
50
|
+
node.callee.object.type !== 'Identifier' ||
|
|
51
|
+
node.callee.object.name !== object
|
|
52
|
+
) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
57
55
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
56
|
+
|
|
57
|
+
if (property) {
|
|
58
|
+
if (
|
|
59
|
+
!node.callee.property ||
|
|
60
|
+
node.callee.property.type !== 'Identifier' ||
|
|
61
|
+
node.callee.property.name !== property
|
|
62
|
+
) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
63
65
|
}
|
|
66
|
+
return true;
|
|
64
67
|
}
|
|
65
|
-
return
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (node.callee.type === 'Identifier') {
|
|
68
72
|
const { callee } = astInfo;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return true;
|
|
73
|
+
if (callee && !astInfo.object && !astInfo.property) {
|
|
74
|
+
return node.callee.name === callee;
|
|
72
75
|
}
|
|
73
76
|
}
|
|
74
77
|
|
|
@@ -155,10 +158,25 @@ const checkMap = {
|
|
|
155
158
|
default: () => false,
|
|
156
159
|
};
|
|
157
160
|
|
|
161
|
+
const formatError = (filePath, error) => {
|
|
162
|
+
console.error('error: ES-Check: there were 1 ES version matching errors.');
|
|
163
|
+
console.info(`
|
|
164
|
+
ES-Check Error:
|
|
165
|
+
----
|
|
166
|
+
· erroring file: ${filePath}
|
|
167
|
+
· error: ${error.message}
|
|
168
|
+
· see the printed err.stack below for context
|
|
169
|
+
----
|
|
170
|
+
|
|
171
|
+
${error.stack}
|
|
172
|
+
`);
|
|
173
|
+
};
|
|
174
|
+
|
|
158
175
|
module.exports = {
|
|
159
176
|
checkVarKindMatch,
|
|
160
177
|
checkCalleeMatch,
|
|
161
178
|
checkOperatorMatch,
|
|
162
179
|
checkDefault,
|
|
163
180
|
checkMap,
|
|
181
|
+
formatError,
|
|
164
182
|
};
|