@microsoft/sp-tslint-rules 1.20.2 → 1.21.0-beta.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/lib-commonjs/importRequiresChunkNameRule.js +130 -0
- package/lib-commonjs/index.js +9 -0
- package/lib-commonjs/noAsyncAwaitRule.js +102 -0
- package/lib-commonjs/noRequireEnsureRule.js +95 -0
- package/lib-commonjs/pairReactDomRenderUnmountRule.js +136 -0
- package/lib-commonjs/scripts/runTslintTests.js +69 -0
- package/lib-commonjs/validKillSwitchGuidRule.js +100 -0
- package/lib-dts/scripts/runTslintTests.d.ts +3 -0
- package/{lib → lib-esm}/importRequiresChunkNameRule.js +30 -48
- package/lib-esm/index.js +6 -0
- package/lib-esm/noAsyncAwaitRule.js +55 -0
- package/lib-esm/noRequireEnsureRule.js +44 -0
- package/lib-esm/pairReactDomRenderUnmountRule.js +85 -0
- package/lib-esm/scripts/runTslintTests.js +18 -0
- package/lib-esm/validKillSwitchGuidRule.js +53 -0
- package/package.json +29 -7
- package/base-tslint.json +0 -5
- package/lib/importRequiresChunkNameRule.d.ts.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -7
- package/lib/noAsyncAwaitRule.d.ts.map +0 -1
- package/lib/noAsyncAwaitRule.js +0 -73
- package/lib/noRequireEnsureRule.d.ts.map +0 -1
- package/lib/noRequireEnsureRule.js +0 -60
- package/lib/pairReactDomRenderUnmountRule.d.ts.map +0 -1
- package/lib/pairReactDomRenderUnmountRule.js +0 -108
- package/lib/validKillSwitchGuidRule.d.ts.map +0 -1
- package/lib/validKillSwitchGuidRule.js +0 -72
- /package/{lib → lib-dts}/importRequiresChunkNameRule.d.ts +0 -0
- /package/{lib → lib-dts}/index.d.ts +0 -0
- /package/{lib → lib-dts}/noAsyncAwaitRule.d.ts +0 -0
- /package/{lib → lib-dts}/noRequireEnsureRule.d.ts +0 -0
- /package/{lib → lib-dts}/pairReactDomRenderUnmountRule.d.ts +0 -0
- /package/{lib → lib-dts}/validKillSwitchGuidRule.d.ts +0 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "Rule", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return Rule;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _tsutils = require("tsutils");
|
|
12
|
+
const _typescript = /*#__PURE__*/ _interop_require_wildcard(require("typescript"));
|
|
13
|
+
const _tslint = /*#__PURE__*/ _interop_require_wildcard(require("tslint"));
|
|
14
|
+
function _define_property(obj, key, value) {
|
|
15
|
+
if (key in obj) {
|
|
16
|
+
Object.defineProperty(obj, key, {
|
|
17
|
+
value: value,
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true
|
|
21
|
+
});
|
|
22
|
+
} else {
|
|
23
|
+
obj[key] = value;
|
|
24
|
+
}
|
|
25
|
+
return obj;
|
|
26
|
+
}
|
|
27
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
28
|
+
if (typeof WeakMap !== "function") return null;
|
|
29
|
+
var cacheBabelInterop = new WeakMap();
|
|
30
|
+
var cacheNodeInterop = new WeakMap();
|
|
31
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
32
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
33
|
+
})(nodeInterop);
|
|
34
|
+
}
|
|
35
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
36
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
37
|
+
return obj;
|
|
38
|
+
}
|
|
39
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
40
|
+
return {
|
|
41
|
+
default: obj
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
45
|
+
if (cache && cache.has(obj)) {
|
|
46
|
+
return cache.get(obj);
|
|
47
|
+
}
|
|
48
|
+
var newObj = {
|
|
49
|
+
__proto__: null
|
|
50
|
+
};
|
|
51
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
52
|
+
for(var key in obj){
|
|
53
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
54
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
55
|
+
if (desc && (desc.get || desc.set)) {
|
|
56
|
+
Object.defineProperty(newObj, key, desc);
|
|
57
|
+
} else {
|
|
58
|
+
newObj[key] = obj[key];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
newObj.default = obj;
|
|
63
|
+
if (cache) {
|
|
64
|
+
cache.set(obj, newObj);
|
|
65
|
+
}
|
|
66
|
+
return newObj;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Matches parts of the webpack import(...) meta-comment that look like these examples:
|
|
70
|
+
* - propertyName:'value'
|
|
71
|
+
* - propertyName: 'value'
|
|
72
|
+
* - propertyName:"value"
|
|
73
|
+
* - propertyName: "value"
|
|
74
|
+
* - propertyName :'value'
|
|
75
|
+
* - propertyName : 'value'
|
|
76
|
+
* - propertyName :"value"
|
|
77
|
+
* - propertyName : "value"
|
|
78
|
+
*/ const COMMENT_PART_REGEX = /^([A-Za-z]+)\s*:\s*('[^']+'|"[^"]+")$/;
|
|
79
|
+
var _Lint_Rules_AbstractRule;
|
|
80
|
+
class Rule extends (_Lint_Rules_AbstractRule = _tslint.Rules.AbstractRule) {
|
|
81
|
+
apply(sourceFile) {
|
|
82
|
+
return this.applyWithFunction(sourceFile, (ctx)=>{
|
|
83
|
+
const childCallback = (node)=>{
|
|
84
|
+
if ((0, _tsutils.isCallExpression)(node) && node.expression.kind === _typescript.SyntaxKind.ImportKeyword && node.getChildCount() >= 4 // 4+ children: keyword, openParen, args..., closeParen
|
|
85
|
+
) {
|
|
86
|
+
// In an import(...) expression
|
|
87
|
+
const comments = [];
|
|
88
|
+
(0, _tsutils.forEachComment)(node, (text, comment)=>{
|
|
89
|
+
comments.push(text.substring(comment.pos, comment.end));
|
|
90
|
+
});
|
|
91
|
+
let webpackChunkNameTokensFound = 0;
|
|
92
|
+
for (const rawComment of comments){
|
|
93
|
+
let comment = rawComment.trim();
|
|
94
|
+
if (comment.indexOf('//') === 0) {
|
|
95
|
+
comment = comment.substr(2);
|
|
96
|
+
} else if (comment.indexOf('/*') === 0 && comment.indexOf('*/') === comment.length - 2) {
|
|
97
|
+
comment = comment.substring(2, comment.length - 2);
|
|
98
|
+
}
|
|
99
|
+
const commentParts = comment.split(',');
|
|
100
|
+
for (let commentPart of commentParts){
|
|
101
|
+
commentPart = commentPart.trim();
|
|
102
|
+
const commentRegexResult = commentPart.match(COMMENT_PART_REGEX);
|
|
103
|
+
if (commentRegexResult && commentRegexResult[1] === 'webpackChunkName') {
|
|
104
|
+
webpackChunkNameTokensFound++;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (webpackChunkNameTokensFound === 0) {
|
|
109
|
+
ctx.addFailureAtNode(node.expression, 'Calls to "import" must include a /* webpackChunkName: \'name\' */ comment');
|
|
110
|
+
} else if (webpackChunkNameTokensFound !== 1) {
|
|
111
|
+
ctx.addFailureAtNode(node.expression, 'Calls to "import" must include only one /* webpackChunkName: \'name\' */ comment');
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return _typescript.forEachChild(node, childCallback);
|
|
115
|
+
};
|
|
116
|
+
return _typescript.forEachChild(ctx.sourceFile, childCallback);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
_define_property(Rule, "metadata", {
|
|
121
|
+
ruleName: 'import-requires-chunk-name',
|
|
122
|
+
description: 'Requires that calls to import(...) for code splitting include a webpack chunk name',
|
|
123
|
+
rationale: 'Unnamed chunks are difficult to manage.',
|
|
124
|
+
optionsDescription: 'No options available.',
|
|
125
|
+
options: {},
|
|
126
|
+
type: 'functionality',
|
|
127
|
+
typescriptOnly: false
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
//#sourceMappingUrl=./importRequiresChunkNameRule.js.map
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "Rule", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return Rule;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _tsutils = require("tsutils");
|
|
12
|
+
const _typescript = /*#__PURE__*/ _interop_require_wildcard(require("typescript"));
|
|
13
|
+
const _tslint = /*#__PURE__*/ _interop_require_wildcard(require("tslint"));
|
|
14
|
+
function _define_property(obj, key, value) {
|
|
15
|
+
if (key in obj) {
|
|
16
|
+
Object.defineProperty(obj, key, {
|
|
17
|
+
value: value,
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true
|
|
21
|
+
});
|
|
22
|
+
} else {
|
|
23
|
+
obj[key] = value;
|
|
24
|
+
}
|
|
25
|
+
return obj;
|
|
26
|
+
}
|
|
27
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
28
|
+
if (typeof WeakMap !== "function") return null;
|
|
29
|
+
var cacheBabelInterop = new WeakMap();
|
|
30
|
+
var cacheNodeInterop = new WeakMap();
|
|
31
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
32
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
33
|
+
})(nodeInterop);
|
|
34
|
+
}
|
|
35
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
36
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
37
|
+
return obj;
|
|
38
|
+
}
|
|
39
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
40
|
+
return {
|
|
41
|
+
default: obj
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
45
|
+
if (cache && cache.has(obj)) {
|
|
46
|
+
return cache.get(obj);
|
|
47
|
+
}
|
|
48
|
+
var newObj = {
|
|
49
|
+
__proto__: null
|
|
50
|
+
};
|
|
51
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
52
|
+
for(var key in obj){
|
|
53
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
54
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
55
|
+
if (desc && (desc.get || desc.set)) {
|
|
56
|
+
Object.defineProperty(newObj, key, desc);
|
|
57
|
+
} else {
|
|
58
|
+
newObj[key] = obj[key];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
newObj.default = obj;
|
|
63
|
+
if (cache) {
|
|
64
|
+
cache.set(obj, newObj);
|
|
65
|
+
}
|
|
66
|
+
return newObj;
|
|
67
|
+
}
|
|
68
|
+
var _Lint_Rules_AbstractRule;
|
|
69
|
+
class Rule extends (_Lint_Rules_AbstractRule = _tslint.Rules.AbstractRule) {
|
|
70
|
+
apply(source) {
|
|
71
|
+
return this.applyWithFunction(source, noAsyncAwait);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
_define_property(Rule, "metadata", {
|
|
75
|
+
ruleName: 'no-async-await',
|
|
76
|
+
description: 'Warn when using async/await functions.',
|
|
77
|
+
rationale: 'async/await has overhead when emitting ES5 JavaScript',
|
|
78
|
+
optionsDescription: 'No options available.',
|
|
79
|
+
options: undefined,
|
|
80
|
+
type: 'functionality',
|
|
81
|
+
typescriptOnly: false
|
|
82
|
+
});
|
|
83
|
+
function noAsyncAwait(context, node) {
|
|
84
|
+
if (!node) {
|
|
85
|
+
_typescript.forEachChild(context.sourceFile, (n)=>noAsyncAwait(context, n));
|
|
86
|
+
} else {
|
|
87
|
+
if ((0, _tsutils.isArrowFunction)(node) || (0, _tsutils.isFunctionDeclaration)(node) || (0, _tsutils.isFunctionExpression)(node) || (0, _tsutils.isMethodDeclaration)(node)) {
|
|
88
|
+
checkAndReportIfAsync(context, node);
|
|
89
|
+
}
|
|
90
|
+
_typescript.forEachChild(node, (n)=>noAsyncAwait(context, n));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function checkAndReportIfAsync(context, node) {
|
|
94
|
+
if (node.body === undefined && node.type !== undefined) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (node.modifiers !== undefined && node.modifiers.find((modifier)=>modifier.kind === _typescript.SyntaxKind.AsyncKeyword)) {
|
|
98
|
+
context.addFailureAtNode(node, 'async/await usage is not allowed');
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
//#sourceMappingUrl=./noAsyncAwaitRule.js.map
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "Rule", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return Rule;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _tsutils = require("tsutils");
|
|
12
|
+
const _typescript = /*#__PURE__*/ _interop_require_wildcard(require("typescript"));
|
|
13
|
+
const _tslint = /*#__PURE__*/ _interop_require_wildcard(require("tslint"));
|
|
14
|
+
function _define_property(obj, key, value) {
|
|
15
|
+
if (key in obj) {
|
|
16
|
+
Object.defineProperty(obj, key, {
|
|
17
|
+
value: value,
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true
|
|
21
|
+
});
|
|
22
|
+
} else {
|
|
23
|
+
obj[key] = value;
|
|
24
|
+
}
|
|
25
|
+
return obj;
|
|
26
|
+
}
|
|
27
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
28
|
+
if (typeof WeakMap !== "function") return null;
|
|
29
|
+
var cacheBabelInterop = new WeakMap();
|
|
30
|
+
var cacheNodeInterop = new WeakMap();
|
|
31
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
32
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
33
|
+
})(nodeInterop);
|
|
34
|
+
}
|
|
35
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
36
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
37
|
+
return obj;
|
|
38
|
+
}
|
|
39
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
40
|
+
return {
|
|
41
|
+
default: obj
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
45
|
+
if (cache && cache.has(obj)) {
|
|
46
|
+
return cache.get(obj);
|
|
47
|
+
}
|
|
48
|
+
var newObj = {
|
|
49
|
+
__proto__: null
|
|
50
|
+
};
|
|
51
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
52
|
+
for(var key in obj){
|
|
53
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
54
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
55
|
+
if (desc && (desc.get || desc.set)) {
|
|
56
|
+
Object.defineProperty(newObj, key, desc);
|
|
57
|
+
} else {
|
|
58
|
+
newObj[key] = obj[key];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
newObj.default = obj;
|
|
63
|
+
if (cache) {
|
|
64
|
+
cache.set(obj, newObj);
|
|
65
|
+
}
|
|
66
|
+
return newObj;
|
|
67
|
+
}
|
|
68
|
+
var _Lint_Rules_AbstractRule;
|
|
69
|
+
class Rule extends (_Lint_Rules_AbstractRule = _tslint.Rules.AbstractRule) {
|
|
70
|
+
apply(sourceFile) {
|
|
71
|
+
return this.applyWithFunction(sourceFile, (ctx)=>{
|
|
72
|
+
const childCallback = (node)=>{
|
|
73
|
+
if ((0, _tsutils.isCallExpression)(node) && (0, _tsutils.isPropertyAccessExpression)(node.expression) && (0, _tsutils.isIdentifier)(node.expression.expression) && node.expression.expression.text === 'require' && node.expression.getChildCount() === 3) {
|
|
74
|
+
const lastChild = node.expression.getChildAt(2);
|
|
75
|
+
if ((0, _tsutils.isIdentifier)(lastChild) && lastChild.text === 'ensure') {
|
|
76
|
+
ctx.addFailureAtNode(node.expression, "Calls to 'require.ensure' are not allowed. Use 'import' instead.");
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return _typescript.forEachChild(node, childCallback);
|
|
80
|
+
};
|
|
81
|
+
return _typescript.forEachChild(ctx.sourceFile, childCallback);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
_define_property(Rule, "metadata", {
|
|
86
|
+
ruleName: 'no-require-ensure',
|
|
87
|
+
description: 'Warns about the use of the require.ensure function.',
|
|
88
|
+
rationale: '`require.ensure` is outdated. Use `import(...)` instead.',
|
|
89
|
+
optionsDescription: 'No options available.',
|
|
90
|
+
options: {},
|
|
91
|
+
type: 'functionality',
|
|
92
|
+
typescriptOnly: false
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
//#sourceMappingUrl=./noRequireEnsureRule.js.map
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "Rule", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return Rule;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _tsutils = /*#__PURE__*/ _interop_require_wildcard(require("tsutils"));
|
|
12
|
+
const _typescript = /*#__PURE__*/ _interop_require_wildcard(require("typescript"));
|
|
13
|
+
const _tslint = /*#__PURE__*/ _interop_require_wildcard(require("tslint"));
|
|
14
|
+
function _define_property(obj, key, value) {
|
|
15
|
+
if (key in obj) {
|
|
16
|
+
Object.defineProperty(obj, key, {
|
|
17
|
+
value: value,
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true
|
|
21
|
+
});
|
|
22
|
+
} else {
|
|
23
|
+
obj[key] = value;
|
|
24
|
+
}
|
|
25
|
+
return obj;
|
|
26
|
+
}
|
|
27
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
28
|
+
if (typeof WeakMap !== "function") return null;
|
|
29
|
+
var cacheBabelInterop = new WeakMap();
|
|
30
|
+
var cacheNodeInterop = new WeakMap();
|
|
31
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
32
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
33
|
+
})(nodeInterop);
|
|
34
|
+
}
|
|
35
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
36
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
37
|
+
return obj;
|
|
38
|
+
}
|
|
39
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
40
|
+
return {
|
|
41
|
+
default: obj
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
45
|
+
if (cache && cache.has(obj)) {
|
|
46
|
+
return cache.get(obj);
|
|
47
|
+
}
|
|
48
|
+
var newObj = {
|
|
49
|
+
__proto__: null
|
|
50
|
+
};
|
|
51
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
52
|
+
for(var key in obj){
|
|
53
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
54
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
55
|
+
if (desc && (desc.get || desc.set)) {
|
|
56
|
+
Object.defineProperty(newObj, key, desc);
|
|
57
|
+
} else {
|
|
58
|
+
newObj[key] = obj[key];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
newObj.default = obj;
|
|
63
|
+
if (cache) {
|
|
64
|
+
cache.set(obj, newObj);
|
|
65
|
+
}
|
|
66
|
+
return newObj;
|
|
67
|
+
}
|
|
68
|
+
var _Lint_Rules_AbstractRule;
|
|
69
|
+
class Rule extends (_Lint_Rules_AbstractRule = _tslint.Rules.AbstractRule) {
|
|
70
|
+
apply(sourceFile) {
|
|
71
|
+
return this.applyWithFunction(sourceFile, this._walk.bind(this));
|
|
72
|
+
}
|
|
73
|
+
_walk(ctx) {
|
|
74
|
+
const renderCalls = [];
|
|
75
|
+
const unmountCalls = [];
|
|
76
|
+
// Do not convert `callback` to a function. It references `this` keyword inside it.
|
|
77
|
+
const callback = (node)=>{
|
|
78
|
+
const reactDOMImportNamespaceName = this._getReactDOMImportNamespaceName(node);
|
|
79
|
+
if (reactDOMImportNamespaceName) {
|
|
80
|
+
this._reactDOMImportNamespaceName = reactDOMImportNamespaceName;
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const isRenderCallExpression = this._isReactDOMCallExpression(node, 'render');
|
|
84
|
+
if (isRenderCallExpression) {
|
|
85
|
+
renderCalls.push(node);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const isUnmountCallExpression = this._isReactDOMCallExpression(node, 'unmountComponentAtNode');
|
|
89
|
+
if (isUnmountCallExpression) {
|
|
90
|
+
unmountCalls.push(node);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
_typescript.forEachChild(node, callback);
|
|
94
|
+
};
|
|
95
|
+
_typescript.forEachChild(ctx.sourceFile, callback);
|
|
96
|
+
// Verify the count of render calls and unmount calls are the same in the file.
|
|
97
|
+
if (renderCalls.length !== unmountCalls.length) {
|
|
98
|
+
renderCalls.concat(unmountCalls).forEach((renderCallExpression)=>{
|
|
99
|
+
ctx.addFailureAtNode(renderCallExpression, 'Unmatched calls between `ReactDOM.render` and `ReactDOM.unmountComponentAtNode`.');
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
_getReactDOMImportNamespaceName(node) {
|
|
104
|
+
if (// import * as ReactDOM from 'react-dom'
|
|
105
|
+
_tsutils.isImportDeclaration(node) && // * as ReactDOM
|
|
106
|
+
node.importClause && _tsutils.isImportClause(node.importClause) && // ReactDOM
|
|
107
|
+
node.importClause.namedBindings && _tsutils.isNamespaceImport(node.importClause.namedBindings) && // 'react-dom'
|
|
108
|
+
_tsutils.isStringLiteral(node.moduleSpecifier) && node.moduleSpecifier.text === 'react-dom') {
|
|
109
|
+
return node.importClause.namedBindings.name.text;
|
|
110
|
+
} else {
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
_isReactDOMCallExpression(node, methodName) {
|
|
115
|
+
return(// ReactDOM.method(param1, param2)
|
|
116
|
+
_tsutils.isCallExpression(node) && // ReactDOM.method
|
|
117
|
+
_tsutils.isPropertyAccessExpression(node.expression) && // ReactDOM
|
|
118
|
+
_tsutils.isIdentifier(node.expression.expression) && node.expression.expression.text === this._reactDOMImportNamespaceName && // method
|
|
119
|
+
_tsutils.isIdentifier(node.expression.name) && node.expression.name.text === methodName);
|
|
120
|
+
}
|
|
121
|
+
constructor(...args){
|
|
122
|
+
super(...args);
|
|
123
|
+
_define_property(this, "_reactDOMImportNamespaceName", void 0);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
_define_property(Rule, "metadata", {
|
|
127
|
+
ruleName: 'pair-react-dom-render-unmount',
|
|
128
|
+
description: 'Pair ReactDOM render and unmount calls in one file.' + ' If a ReactDOM render tree is not unmounted when disposed, it will cause a memory leak.',
|
|
129
|
+
rationale: 'Pair the render and unmount calls to avoid memory leak.',
|
|
130
|
+
optionsDescription: 'No options available.',
|
|
131
|
+
options: {},
|
|
132
|
+
type: 'maintainability',
|
|
133
|
+
typescriptOnly: false
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
//#sourceMappingUrl=./pairReactDomRenderUnmountRule.js.map
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "runAsync", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return runAsync;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _tslint = /*#__PURE__*/ _interop_require_wildcard(require("tslint"));
|
|
12
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
13
|
+
if (typeof WeakMap !== "function") return null;
|
|
14
|
+
var cacheBabelInterop = new WeakMap();
|
|
15
|
+
var cacheNodeInterop = new WeakMap();
|
|
16
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
17
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
18
|
+
})(nodeInterop);
|
|
19
|
+
}
|
|
20
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
21
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
22
|
+
return obj;
|
|
23
|
+
}
|
|
24
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
25
|
+
return {
|
|
26
|
+
default: obj
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
30
|
+
if (cache && cache.has(obj)) {
|
|
31
|
+
return cache.get(obj);
|
|
32
|
+
}
|
|
33
|
+
var newObj = {
|
|
34
|
+
__proto__: null
|
|
35
|
+
};
|
|
36
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
37
|
+
for(var key in obj){
|
|
38
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
39
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
40
|
+
if (desc && (desc.get || desc.set)) {
|
|
41
|
+
Object.defineProperty(newObj, key, desc);
|
|
42
|
+
} else {
|
|
43
|
+
newObj[key] = obj[key];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
newObj.default = obj;
|
|
48
|
+
if (cache) {
|
|
49
|
+
cache.set(obj, newObj);
|
|
50
|
+
}
|
|
51
|
+
return newObj;
|
|
52
|
+
}
|
|
53
|
+
async function runAsync(options) {
|
|
54
|
+
const { heftTaskSession: { logger } } = options;
|
|
55
|
+
const testResults = _tslint.Test.runTests([
|
|
56
|
+
'test/**/tslint.json'
|
|
57
|
+
], 'lib-commonjs');
|
|
58
|
+
const isSuccess = _tslint.Test.consoleTestResultsHandler(testResults, {
|
|
59
|
+
log: logger.terminal.writeLine.bind(logger.terminal),
|
|
60
|
+
error: logger.terminal.writeErrorLine.bind(logger.terminal)
|
|
61
|
+
});
|
|
62
|
+
if (!isSuccess) {
|
|
63
|
+
const e = new Error('TSLint tests failed.');
|
|
64
|
+
logger.emitError(e);
|
|
65
|
+
throw e;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
//#sourceMappingUrl=./runTslintTests.js.map
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "Rule", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return Rule;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _tslint = /*#__PURE__*/ _interop_require_wildcard(require("tslint"));
|
|
12
|
+
const _tsutils = require("tsutils");
|
|
13
|
+
const _typescript = /*#__PURE__*/ _interop_require_wildcard(require("typescript"));
|
|
14
|
+
function _define_property(obj, key, value) {
|
|
15
|
+
if (key in obj) {
|
|
16
|
+
Object.defineProperty(obj, key, {
|
|
17
|
+
value: value,
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true
|
|
21
|
+
});
|
|
22
|
+
} else {
|
|
23
|
+
obj[key] = value;
|
|
24
|
+
}
|
|
25
|
+
return obj;
|
|
26
|
+
}
|
|
27
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
28
|
+
if (typeof WeakMap !== "function") return null;
|
|
29
|
+
var cacheBabelInterop = new WeakMap();
|
|
30
|
+
var cacheNodeInterop = new WeakMap();
|
|
31
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
32
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
33
|
+
})(nodeInterop);
|
|
34
|
+
}
|
|
35
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
36
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
37
|
+
return obj;
|
|
38
|
+
}
|
|
39
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
40
|
+
return {
|
|
41
|
+
default: obj
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
45
|
+
if (cache && cache.has(obj)) {
|
|
46
|
+
return cache.get(obj);
|
|
47
|
+
}
|
|
48
|
+
var newObj = {
|
|
49
|
+
__proto__: null
|
|
50
|
+
};
|
|
51
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
52
|
+
for(var key in obj){
|
|
53
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
54
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
55
|
+
if (desc && (desc.get || desc.set)) {
|
|
56
|
+
Object.defineProperty(newObj, key, desc);
|
|
57
|
+
} else {
|
|
58
|
+
newObj[key] = obj[key];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
newObj.default = obj;
|
|
63
|
+
if (cache) {
|
|
64
|
+
cache.set(obj, newObj);
|
|
65
|
+
}
|
|
66
|
+
return newObj;
|
|
67
|
+
}
|
|
68
|
+
var _Lint_Rules_AbstractRule;
|
|
69
|
+
class Rule extends (_Lint_Rules_AbstractRule = _tslint.Rules.AbstractRule) {
|
|
70
|
+
apply(source) {
|
|
71
|
+
return this.applyWithFunction(source, validKillSwitchGuid);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
_define_property(Rule, "metadata", {
|
|
75
|
+
ruleName: 'valid-kill-switch-guid',
|
|
76
|
+
description: 'Warn if _SPKillSwitch.isActivated is being called with an incorrect argument',
|
|
77
|
+
rationale: 'Compile time type safety',
|
|
78
|
+
optionsDescription: 'No options available.',
|
|
79
|
+
options: undefined,
|
|
80
|
+
type: 'functionality',
|
|
81
|
+
typescriptOnly: false
|
|
82
|
+
});
|
|
83
|
+
function validKillSwitchGuid(context, node) {
|
|
84
|
+
if (!node) {
|
|
85
|
+
_typescript.forEachChild(context.sourceFile, (n)=>validKillSwitchGuid(context, n));
|
|
86
|
+
} else {
|
|
87
|
+
if ((0, _tsutils.isCallExpression)(node) && isSPKillSwitch(node) && !isValidGuid(node.arguments[0].getText())) {
|
|
88
|
+
context.addFailureAtNode(node, '_SPKillSwitch.isActivated argument must be a valid, lower-case GUID');
|
|
89
|
+
}
|
|
90
|
+
_typescript.forEachChild(node, (n)=>validKillSwitchGuid(context, n));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function isSPKillSwitch(node) {
|
|
94
|
+
return (0, _tsutils.isPropertyAccessExpression)(node.expression) && node.expression.name.getText() === 'isActivated' && (0, _tsutils.isIdentifier)(node.expression.expression) && (node.expression.expression.getText() === '_SPKillSwitch' || node.expression.expression.getText() === 'SPKillSwitch') && node.arguments.length === 1;
|
|
95
|
+
}
|
|
96
|
+
function isValidGuid(guidString) {
|
|
97
|
+
return /^'[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}'$/.test(guidString);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
//#sourceMappingUrl=./validKillSwitchGuidRule.js.map
|