@microsoft/sp-tslint-rules 1.21.0-beta.0 → 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.
Files changed (34) hide show
  1. package/lib-commonjs/importRequiresChunkNameRule.js +130 -0
  2. package/lib-commonjs/index.js +9 -0
  3. package/lib-commonjs/noAsyncAwaitRule.js +102 -0
  4. package/lib-commonjs/noRequireEnsureRule.js +95 -0
  5. package/lib-commonjs/pairReactDomRenderUnmountRule.js +136 -0
  6. package/lib-commonjs/scripts/runTslintTests.js +69 -0
  7. package/lib-commonjs/validKillSwitchGuidRule.js +100 -0
  8. package/lib-dts/scripts/runTslintTests.d.ts +3 -0
  9. package/{lib → lib-esm}/importRequiresChunkNameRule.js +30 -48
  10. package/lib-esm/index.js +6 -0
  11. package/lib-esm/noAsyncAwaitRule.js +55 -0
  12. package/lib-esm/noRequireEnsureRule.js +44 -0
  13. package/lib-esm/pairReactDomRenderUnmountRule.js +85 -0
  14. package/lib-esm/scripts/runTslintTests.js +18 -0
  15. package/lib-esm/validKillSwitchGuidRule.js +53 -0
  16. package/package.json +27 -5
  17. package/base-tslint.json +0 -5
  18. package/lib/importRequiresChunkNameRule.d.ts.map +0 -1
  19. package/lib/index.d.ts.map +0 -1
  20. package/lib/index.js +0 -7
  21. package/lib/noAsyncAwaitRule.d.ts.map +0 -1
  22. package/lib/noAsyncAwaitRule.js +0 -73
  23. package/lib/noRequireEnsureRule.d.ts.map +0 -1
  24. package/lib/noRequireEnsureRule.js +0 -60
  25. package/lib/pairReactDomRenderUnmountRule.d.ts.map +0 -1
  26. package/lib/pairReactDomRenderUnmountRule.js +0 -108
  27. package/lib/validKillSwitchGuidRule.d.ts.map +0 -1
  28. package/lib/validKillSwitchGuidRule.js +0 -72
  29. /package/{lib → lib-dts}/importRequiresChunkNameRule.d.ts +0 -0
  30. /package/{lib → lib-dts}/index.d.ts +0 -0
  31. /package/{lib → lib-dts}/noAsyncAwaitRule.d.ts +0 -0
  32. /package/{lib → lib-dts}/noRequireEnsureRule.d.ts +0 -0
  33. /package/{lib → lib-dts}/pairReactDomRenderUnmountRule.d.ts +0 -0
  34. /package/{lib → lib-dts}/validKillSwitchGuidRule.d.ts +0 -0
@@ -1,108 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.Rule = void 0;
27
- const tsUtils = __importStar(require("tsutils"));
28
- const ts = __importStar(require("typescript"));
29
- const Lint = __importStar(require("tslint"));
30
- class Rule extends Lint.Rules.AbstractRule {
31
- apply(sourceFile) {
32
- return this.applyWithFunction(sourceFile, this._walk.bind(this));
33
- }
34
- _walk(ctx) {
35
- const renderCalls = [];
36
- const unmountCalls = [];
37
- // Do not convert `callback` to a function. It references `this` keyword inside it.
38
- const callback = (node) => {
39
- const reactDOMImportNamespaceName = this._getReactDOMImportNamespaceName(node);
40
- if (reactDOMImportNamespaceName) {
41
- this._reactDOMImportNamespaceName = reactDOMImportNamespaceName;
42
- return;
43
- }
44
- const isRenderCallExpression = this._isReactDOMCallExpression(node, 'render');
45
- if (isRenderCallExpression) {
46
- renderCalls.push(node);
47
- return;
48
- }
49
- const isUnmountCallExpression = this._isReactDOMCallExpression(node, 'unmountComponentAtNode');
50
- if (isUnmountCallExpression) {
51
- unmountCalls.push(node);
52
- return;
53
- }
54
- ts.forEachChild(node, callback);
55
- };
56
- ts.forEachChild(ctx.sourceFile, callback);
57
- // Verify the count of render calls and unmount calls are the same in the file.
58
- if (renderCalls.length !== unmountCalls.length) {
59
- renderCalls.concat(unmountCalls).forEach((renderCallExpression) => {
60
- ctx.addFailureAtNode(renderCallExpression, 'Unmatched calls between `ReactDOM.render` and `ReactDOM.unmountComponentAtNode`.');
61
- });
62
- }
63
- }
64
- _getReactDOMImportNamespaceName(node) {
65
- if (
66
- // import * as ReactDOM from 'react-dom'
67
- tsUtils.isImportDeclaration(node) &&
68
- // * as ReactDOM
69
- node.importClause &&
70
- tsUtils.isImportClause(node.importClause) &&
71
- // ReactDOM
72
- node.importClause.namedBindings &&
73
- tsUtils.isNamespaceImport(node.importClause.namedBindings) &&
74
- // 'react-dom'
75
- tsUtils.isStringLiteral(node.moduleSpecifier) &&
76
- node.moduleSpecifier.text === 'react-dom') {
77
- return node.importClause.namedBindings.name.text;
78
- }
79
- else {
80
- return undefined;
81
- }
82
- }
83
- _isReactDOMCallExpression(node, methodName) {
84
- return (
85
- // ReactDOM.method(param1, param2)
86
- tsUtils.isCallExpression(node) &&
87
- // ReactDOM.method
88
- tsUtils.isPropertyAccessExpression(node.expression) &&
89
- // ReactDOM
90
- tsUtils.isIdentifier(node.expression.expression) &&
91
- node.expression.expression.text === this._reactDOMImportNamespaceName &&
92
- // method
93
- tsUtils.isIdentifier(node.expression.name) &&
94
- node.expression.name.text === methodName);
95
- }
96
- }
97
- exports.Rule = Rule;
98
- Rule.metadata = {
99
- ruleName: 'pair-react-dom-render-unmount',
100
- description: 'Pair ReactDOM render and unmount calls in one file.' +
101
- ' If a ReactDOM render tree is not unmounted when disposed, it will cause a memory leak.',
102
- rationale: 'Pair the render and unmount calls to avoid memory leak.',
103
- optionsDescription: 'No options available.',
104
- options: {},
105
- type: 'maintainability',
106
- typescriptOnly: false
107
- };
108
- //# sourceMappingURL=pairReactDomRenderUnmountRule.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validKillSwitchGuidRule.d.ts","sourceRoot":"","sources":["../src/validKillSwitchGuidRule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAE/B,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAEjC;;;;GAIG;AACH,qBAAa,IAAK,SAAQ,IAAI,CAAC,KAAK,CAAC,YAAY;IAC/C,OAAc,QAAQ,EAAE,IAAI,CAAC,aAAa,CAQxC;IAEK,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC,UAAU,GAAG,IAAI,CAAC,WAAW,EAAE;CAGxD"}
@@ -1,72 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.Rule = void 0;
27
- const Lint = __importStar(require("tslint"));
28
- const tsutils_1 = require("tsutils");
29
- const ts = __importStar(require("typescript"));
30
- /**
31
- * Validate valid GUID strings are being passed as an argument to SPKillSwitch.isActivated calls.
32
- * JavaScript does not have a native GUID type. We removed expensive runtime parsing during production
33
- * builds when checking kill switches. In order to ensure type safety, we are validating at build time with tslint.
34
- */
35
- class Rule extends Lint.Rules.AbstractRule {
36
- apply(source) {
37
- return this.applyWithFunction(source, validKillSwitchGuid);
38
- }
39
- }
40
- exports.Rule = Rule;
41
- Rule.metadata = {
42
- ruleName: 'valid-kill-switch-guid',
43
- description: 'Warn if _SPKillSwitch.isActivated is being called with an incorrect argument',
44
- rationale: 'Compile time type safety',
45
- optionsDescription: 'No options available.',
46
- options: undefined,
47
- type: 'functionality',
48
- typescriptOnly: false
49
- };
50
- function validKillSwitchGuid(context, node) {
51
- if (!node) {
52
- ts.forEachChild(context.sourceFile, (n) => validKillSwitchGuid(context, n));
53
- }
54
- else {
55
- if ((0, tsutils_1.isCallExpression)(node) && isSPKillSwitch(node) && !isValidGuid(node.arguments[0].getText())) {
56
- context.addFailureAtNode(node, '_SPKillSwitch.isActivated argument must be a valid, lower-case GUID');
57
- }
58
- ts.forEachChild(node, (n) => validKillSwitchGuid(context, n));
59
- }
60
- }
61
- function isSPKillSwitch(node) {
62
- return ((0, tsutils_1.isPropertyAccessExpression)(node.expression) &&
63
- node.expression.name.getText() === 'isActivated' &&
64
- (0, tsutils_1.isIdentifier)(node.expression.expression) &&
65
- (node.expression.expression.getText() === '_SPKillSwitch' ||
66
- node.expression.expression.getText() === 'SPKillSwitch') &&
67
- node.arguments.length === 1);
68
- }
69
- function isValidGuid(guidString) {
70
- return /^'[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}'$/.test(guidString);
71
- }
72
- //# sourceMappingURL=validKillSwitchGuidRule.js.map
File without changes
File without changes
File without changes
File without changes