@magicspace/tslint-rules
Advanced tools
Comparing version 0.1.16 to 0.1.17
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const Path = require("path"); | ||
const resolve = require("resolve"); | ||
const tslib_1 = require("tslib"); | ||
const Path = tslib_1.__importStar(require("path")); | ||
const resolve_1 = tslib_1.__importDefault(require("resolve")); | ||
const tslint_1 = require("tslint"); | ||
const tsutils_1 = require("tsutils"); | ||
const TypeScript = require("typescript"); | ||
const TypeScript = tslib_1.__importStar(require("typescript")); | ||
const path_1 = require("../utils/path"); | ||
@@ -13,18 +14,2 @@ const ERROR_MESSAGE_UNEXPECTED_EMPTY_LINE = 'Unexpected empty line within the same import group.'; | ||
const ERROR_MESSAGE_NOT_GROUPED = 'Imports must be grouped.'; | ||
const resolveWithCache = (() => { | ||
let cache = new Map(); | ||
return (id, basedir) => { | ||
let key = `${id}\n${basedir}`; | ||
if (cache.has(key)) { | ||
return cache.get(key); | ||
} | ||
let value; | ||
try { | ||
value = resolve.sync(id, { basedir }); | ||
} | ||
catch (error) { } | ||
cache.set(key, value); | ||
return value; | ||
}; | ||
})(); | ||
const BUILT_IN_MODULE_GROUP_TESTER_DICT = { | ||
@@ -41,4 +26,7 @@ '$node-core'(path) { | ||
let basedir = Path.dirname(sourceFilePath); | ||
let resolvedPath = resolveWithCache(modulePath, basedir); | ||
if (!resolvedPath) { | ||
let resolvedPath; | ||
try { | ||
resolvedPath = resolve_1.default.sync(modulePath, { basedir }); | ||
} | ||
catch (error) { | ||
return false; | ||
@@ -51,8 +39,10 @@ } | ||
class ModuleGroup { | ||
constructor({ name, test: testConfig }) { | ||
constructor({ name, test: testConfig, sideEffect }) { | ||
this.name = name; | ||
this.tester = this.buildTester(testConfig); | ||
this.sideEffect = sideEffect; | ||
} | ||
test(modulePath, sourceFilePath) { | ||
return this.tester(modulePath, sourceFilePath); | ||
match(modulePath, sideEffect, sourceFilePath) { | ||
return ((this.sideEffect === undefined || this.sideEffect === sideEffect) && | ||
this.tester(modulePath, sourceFilePath)); | ||
} | ||
@@ -134,7 +124,7 @@ buildTester(config) { | ||
let pendingCache = []; | ||
let checkWithAppendModuleImport = (expression) => { | ||
let checkWithAppendModuleImport = (expression, sideEffect) => { | ||
this.pendingStatements.push(...pendingCache); | ||
pendingCache = []; | ||
if (tsutils_1.isTextualLiteral(expression)) { | ||
this.appendModuleImport(expression, sourceFile); | ||
this.appendModuleImport(expression, sideEffect, sourceFile); | ||
} | ||
@@ -145,3 +135,3 @@ }; | ||
if (1 /* ImportDeclaration */) { | ||
checkWithAppendModuleImport(statement.moduleSpecifier); | ||
checkWithAppendModuleImport(statement.moduleSpecifier, !statement.importClause); | ||
} | ||
@@ -154,3 +144,3 @@ } | ||
statement.moduleReference.expression !== undefined) { | ||
checkWithAppendModuleImport(statement.moduleReference.expression); | ||
checkWithAppendModuleImport(statement.moduleReference.expression, false); | ||
} | ||
@@ -164,3 +154,3 @@ } | ||
} | ||
appendModuleImport(expression, sourceFile) { | ||
appendModuleImport(expression, sideEffect, sourceFile) { | ||
let node = expression; | ||
@@ -172,4 +162,8 @@ while (node.parent.kind !== TypeScript.SyntaxKind.SourceFile) { | ||
let sourceFilePath = sourceFile.fileName; | ||
let comments = node.getFullText(); | ||
comments = comments.slice(comments.indexOf('/'), comments.length); | ||
let commentLine = (comments.match(/\n/g) || []).length - | ||
(comments.match(/\n\n/g) || []).length; | ||
let groups = this.options.groups; | ||
let index = groups.findIndex(group => group.test(modulePath, sourceFilePath)); | ||
let index = groups.findIndex(group => group.match(modulePath, sideEffect, sourceFilePath)); | ||
this.moduleImportInfos.push({ | ||
@@ -179,3 +173,4 @@ node, | ||
groupIndex: index < 0 ? groups.length : index, | ||
startLine: sourceFile.getLineAndCharacterOfPosition(node.getStart()).line, | ||
startLine: sourceFile.getLineAndCharacterOfPosition(node.getStart()).line - | ||
commentLine, | ||
endLine: sourceFile.getLineAndCharacterOfPosition(node.getEnd()).line, | ||
@@ -182,0 +177,0 @@ }); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const FS = require("fs"); | ||
const Path = require("path"); | ||
const tslib_1 = require("tslib"); | ||
const FS = tslib_1.__importStar(require("fs")); | ||
const Path = tslib_1.__importStar(require("path")); | ||
const tslint_1 = require("tslint"); | ||
@@ -6,0 +7,0 @@ const tsutils_1 = require("tsutils"); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const Path = require("path"); | ||
const tslib_1 = require("tslib"); | ||
const Path = tslib_1.__importStar(require("path")); | ||
const tslint_1 = require("tslint"); | ||
@@ -5,0 +6,0 @@ const tsutils_1 = require("tsutils"); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const FS = require("fs"); | ||
const Path = require("path"); | ||
const _ = require("lodash"); | ||
const tslib_1 = require("tslib"); | ||
const FS = tslib_1.__importStar(require("fs")); | ||
const Path = tslib_1.__importStar(require("path")); | ||
const lodash_1 = tslib_1.__importDefault(require("lodash")); | ||
const tslint_1 = require("tslint"); | ||
@@ -117,3 +118,3 @@ const tsutils_1 = require("tsutils"); | ||
.filter((entryName) => !!entryName); | ||
let missingExportIds = _.difference(expectedExportSpecifiers, exportSpecifiers); | ||
let missingExportIds = lodash_1.default.difference(expectedExportSpecifiers, exportSpecifiers); | ||
if (missingExportIds.length) { | ||
@@ -120,0 +121,0 @@ this.failureManager.append({ |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const Path = require("path"); | ||
const tslib_1 = require("tslib"); | ||
const Path = tslib_1.__importStar(require("path")); | ||
const KNOWN_MODULE_EXTENSION_REGEX = /\.(?:jsx?|tsx?)$/i; | ||
@@ -5,0 +6,0 @@ function removeQuotes(value) { |
{ | ||
"name": "@magicspace/tslint-rules", | ||
"version": "0.1.16", | ||
"version": "0.1.17", | ||
"description": "Custom TSLint rules for MagicSpace.", | ||
@@ -10,4 +10,5 @@ "repository": "https://github.com/makeflow/magicspace.git", | ||
"build": "rimraf bld && tsc -p .", | ||
"test": "yarn build && yarn bare-test", | ||
"bare-test": "node ./bld/test/runner.js" | ||
"test": "yarn build && yarn bare-test && yarn lint", | ||
"bare-test": "node ./bld/test/runner.js", | ||
"lint": "yarn tslint -p tsconfig.json" | ||
}, | ||
@@ -14,0 +15,0 @@ "files": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41618
11
1079