tbonelee commented on code in PR #5053: URL: https://github.com/apache/zeppelin/pull/5053#discussion_r2309884980
########## zeppelin-web-angular/tslint-rules/constructorParamsOrderRule.ts: ########## @@ -48,9 +48,9 @@ function walk(ctx: Lint.WalkContext<void>) { // For keeping comment const paramSlices = params.map((p, idx) => { - const start = p.getStart(); + let start = p.getFullStart(); Review Comment: Let's change `let` to `const` ########## zeppelin-web-angular/package.json: ########## @@ -101,4 +102,4 @@ "pre-commit": "lint-staged" } } -} +} Review Comment: New lines are needed before EOF ########## zeppelin-web-angular/tslint-rules/constructorParamsOrderRule.ts: ########## @@ -0,0 +1,119 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import * as Lint from 'tslint'; +import * as ts from 'typescript'; + +export class Rule extends Lint.Rules.AbstractRule { + public static FAILURE_STRING = 'Constructor parameters should be ordered: public, protected, private'; + + public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { + return this.applyWithFunction(sourceFile, walk); + } +} + +function walk(ctx: Lint.WalkContext<void>) { + const checkNode = (node: ts.Node) => { + if (ts.isConstructorDeclaration(node)) { + const params = node.parameters; + if (params.length <= 1) { + return; + } + + const rankMap: Record<string, number> = { public: 0, protected: 1, private: 2, none: 3, optional: 4 }; + const getModifierRank = (param: ts.ParameterDeclaration) => rankMap[getModifier(param)]; + + let lastRank = -1; + let needFix = false; + for (let i = 0; i < params.length; i++) { + const currentRank = getModifierRank(params[i]); + if (currentRank < lastRank) { + needFix = true; + break; + } + lastRank = currentRank; + } + + if (needFix) { + const sourceText = node.getSourceFile().text; + + // For keeping comment + const paramSlices = params.map((p, idx) => { + let start = p.getFullStart(); Review Comment: Did you change `getStart()` to `getFullStart()` to fix the `fixText` variable result? Just curious. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: reviews-unsubscr...@zeppelin.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org