@magicspace/tslint-rules
Advanced tools
Comparing version 0.1.25 to 0.1.26
@@ -53,3 +53,3 @@ "use strict"; | ||
if (tsutils_1.isConstructorDeclaration(node)) { | ||
this.walkConstructorDeclaration(node); | ||
this.walkFunctionLikeDeclaration(node); | ||
} | ||
@@ -59,3 +59,3 @@ else if (tsutils_1.isFunctionDeclaration(node) || tsutils_1.isMethodDeclaration(node)) { | ||
if (!tsutils_1.isObjectLiteralExpression(node.parent)) { | ||
this.walkFunctionOrMethodDeclaration(node); | ||
this.walkFunctionLikeDeclaration(node); | ||
} | ||
@@ -84,22 +84,11 @@ } | ||
} | ||
walkConstructorDeclaration(node) { | ||
walkFunctionLikeDeclaration(node) { | ||
if (node.body) { | ||
let firstSignature = getConstructorFirstSignature(node); | ||
if (firstSignature) { | ||
if (!this.checkBlockIncludingStatement(firstSignature)) { | ||
this.failureManager.append({ | ||
node: firstSignature, | ||
message: ERROR_MESSAGE_EMPTY_LINE_AROUND_STATEMENT_REQUIRED, | ||
replacement: this.buildFixer(firstSignature), | ||
}); | ||
} | ||
this.walkNextAffectedNode(node); | ||
return; | ||
let firstSignature; | ||
if (tsutils_1.isConstructorDeclaration(node)) { | ||
firstSignature = getConstructorFirstSignature(node); | ||
} | ||
this.walkBlockIncludingStatement(node); | ||
} | ||
} | ||
walkFunctionOrMethodDeclaration(node) { | ||
if (node.body) { | ||
let firstSignature = getFirstSignature(node); | ||
else { | ||
firstSignature = getFirstSignature(node); | ||
} | ||
if (firstSignature) { | ||
@@ -203,3 +192,5 @@ if (!this.checkBlockIncludingStatement(firstSignature)) { | ||
} | ||
else if (tsutils_1.isClassDeclaration(parent) || tsutils_1.isInterfaceDeclaration(parent)) { | ||
else if (tsutils_1.isClassDeclaration(parent) || | ||
tsutils_1.isInterfaceDeclaration(parent) || | ||
typescript_1.isClassExpression(parent)) { | ||
return parent.getChildAt(siblingCount - 2); | ||
@@ -206,0 +197,0 @@ } |
@@ -9,3 +9,3 @@ "use strict"; | ||
const ERROR_MESSAGE_EXPLICIT_RETURN_TYPE_REQUIRED = 'This function requires explicit return type.'; | ||
exports.BASE_TYPE_STRING_SET = new Set([ | ||
exports.PRIMITIVE_TYPE_STRING_SET = new Set([ | ||
'boolean', | ||
@@ -21,2 +21,3 @@ 'number', | ||
]); | ||
const PROMISE_RETURN_TYPE_REGEX = /^Promise<(.+)>$/; | ||
class Rule extends tslint_1.Rules.TypedRule { | ||
@@ -81,4 +82,9 @@ constructor(options) { | ||
let returnTypeString = this.typeChecker.typeToString(returnType); | ||
let primitiveReturnType = returnTypeString; | ||
let promiseMatchResult = returnTypeString.match(PROMISE_RETURN_TYPE_REGEX); | ||
if (isModifiedWithAsync(node) && promiseMatchResult) { | ||
primitiveReturnType = promiseMatchResult[1]; | ||
} | ||
if (!this.options.complexTypeFixer && | ||
!exports.BASE_TYPE_STRING_SET.has(returnTypeString)) { | ||
!exports.PRIMITIVE_TYPE_STRING_SET.has(primitiveReturnType)) { | ||
return undefined; | ||
@@ -167,2 +173,13 @@ } | ||
} | ||
function isModifiedWithAsync(node) { | ||
let { modifiers } = node; | ||
if (modifiers && modifiers.length) { | ||
for (let modifier of modifiers) { | ||
if (modifier.kind === typescript_1.SyntaxKind.AsyncKeyword) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
//# sourceMappingURL=explicitReturnTypeRule.js.map |
@@ -53,3 +53,3 @@ "use strict"; | ||
this.sourceDir = Path.dirname(sourceFile.fileName); | ||
let baseUrlDir = (this.baseUrlDir = searchBaseUrlDir(this.sourceDir, options.baseUrlDirSearchName || 'tsconfig.json')); | ||
let baseUrlDir = (this.baseUrlDir = path_1.searchProjectRootDir(this.sourceDir, options.baseUrlDirSearchName || 'tsconfig.json')); | ||
let baseUrlNames = FS.readdirSync(baseUrlDir).reduce((names, entryName) => { | ||
@@ -136,16 +136,2 @@ let entryPath = Path.join(baseUrlDir, entryName); | ||
exports.ImportPathBaseUrlWalker = ImportPathBaseUrlWalker; | ||
function searchBaseUrlDir(from, searchName) { | ||
let nextDir = from; | ||
while (true) { | ||
let currentDir = nextDir; | ||
let searchPath = Path.join(currentDir, searchName); | ||
if (FS.existsSync(searchPath)) { | ||
return currentDir; | ||
} | ||
nextDir = Path.dirname(currentDir); | ||
if (nextDir === currentDir) { | ||
throw new Error(`Cannot find base url directory by search name "${searchName}"`); | ||
} | ||
} | ||
} | ||
function formatModulePath(path, relative) { | ||
@@ -152,0 +138,0 @@ path = path_1.removeModuleFileExtension(path).replace(/\\/g, '/'); |
@@ -18,2 +18,3 @@ "use strict"; | ||
const BANNED_EXPORT_REGEX = /[\\/]@/; | ||
const BANNED_EXPORT_REGEX_FOR_AT_PREFFIXED = /^\.[\\/]@(?:.*?)[\\/]@/; | ||
class Rule extends tslint_1.Rules.AbstractRule { | ||
@@ -74,2 +75,7 @@ apply(sourceFile) { | ||
message = ERROR_MESSAGE_BANNED_EXPORT; | ||
let fileName = statement.getSourceFile().fileName; | ||
let baseName = path_1.getBaseNameWithoutExtension(fileName); | ||
if (baseName.startsWith('@')) { | ||
bannedPattern = BANNED_EXPORT_REGEX_FOR_AT_PREFFIXED; | ||
} | ||
} | ||
@@ -80,3 +86,5 @@ if (bannedPattern.test(specifier)) { | ||
node: statement, | ||
replacement: buildBannedImportsAndExportsFixer(statement), | ||
replacement: type === 'export' | ||
? buildBannedImportsAndExportsFixer(statement) | ||
: undefined, | ||
}); | ||
@@ -91,7 +99,20 @@ } | ||
let dirName = Path.dirname(fileName); | ||
let fileNames = FS.readdirSync(dirName); | ||
let fileNames; | ||
try { | ||
fileNames = FS.readdirSync(dirName); | ||
} | ||
catch (error) { | ||
console.error(`Index validation aborted due to failure of reading: ${dirName}`); | ||
return; | ||
} | ||
let expectedExportSpecifiers = fileNames | ||
.map((fileName) => { | ||
let entryFullPath = Path.join(dirName, fileName); | ||
let stats = FS.statSync(entryFullPath); | ||
let stats; | ||
try { | ||
stats = FS.statSync(entryFullPath); | ||
} | ||
catch (error) { | ||
return undefined; | ||
} | ||
let specifier; | ||
@@ -106,3 +127,9 @@ if (stats.isFile()) { | ||
else if (stats.isDirectory()) { | ||
let entryNamesInFolder = FS.readdirSync(entryFullPath); | ||
let entryNamesInFolder; | ||
try { | ||
entryNamesInFolder = FS.readdirSync(entryFullPath); | ||
} | ||
catch (error) { | ||
return undefined; | ||
} | ||
let hasIndexFile = entryNamesInFolder.some(entryNameInFolder => INDEX_FILE_REGEX.test(entryNameInFolder)); | ||
@@ -109,0 +136,0 @@ if (!hasIndexFile) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
const FS = tslib_1.__importStar(require("fs")); | ||
const Path = tslib_1.__importStar(require("path")); | ||
@@ -23,2 +24,17 @@ const KNOWN_MODULE_EXTENSION_REGEX = /\.(?:jsx?|tsx?)$/i; | ||
exports.getBaseNameWithoutExtension = getBaseNameWithoutExtension; | ||
function searchProjectRootDir(from, searchName) { | ||
let nextDir = from; | ||
while (true) { | ||
let currentDir = nextDir; | ||
let searchPath = Path.join(currentDir, searchName); | ||
if (FS.existsSync(searchPath)) { | ||
return currentDir; | ||
} | ||
nextDir = Path.dirname(currentDir); | ||
if (nextDir === currentDir) { | ||
throw new Error(`Cannot find base url directory by search name "${searchName}"`); | ||
} | ||
} | ||
} | ||
exports.searchProjectRootDir = searchProjectRootDir; | ||
//# sourceMappingURL=path.js.map |
{ | ||
"name": "@magicspace/tslint-rules", | ||
"version": "0.1.25", | ||
"version": "0.1.26", | ||
"description": "Custom TSLint rules for MagicSpace.", | ||
@@ -25,2 +25,3 @@ "repository": "https://github.com/makeflow/magicspace.git", | ||
"resolve": "^1.8.1", | ||
"tslang": "^0.1.9", | ||
"tsutils": "^2.28.0" | ||
@@ -27,0 +28,0 @@ }, |
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
56883
16
1479
6
6
+ Addedtslang@^0.1.9
+ Addedtslang@0.1.27(transitive)