mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Hygiene linting for extensions + new rule (#7843)
* linting for extensions + new rule * Remove unneeded array * Fix spelling mistake * Fix bad merge
This commit is contained in:
@@ -197,7 +197,33 @@ const tslintBaseFilter = [
|
||||
'!extensions/big-data-cluster/src/bigDataCluster/controller/tokenApiGenerated.ts' // {{SQL CARBON EDIT}},
|
||||
];
|
||||
|
||||
const sqlFilter = ['src/sql/**']; // {{SQL CARBON EDIT}}
|
||||
// {{SQL CARBON EDIT}}
|
||||
const sqlFilter = [
|
||||
'src/sql/**',
|
||||
'extensions/**',
|
||||
// Ignore VS Code extensions
|
||||
'!extensions/bat/**',
|
||||
'!extensions/configuration-editing/**',
|
||||
'!extensions/docker/**',
|
||||
'!extensions/extension-editing/**',
|
||||
'!extensions/git/**',
|
||||
'!extensions/git-ui/**',
|
||||
'!extensions/image-preview/**',
|
||||
'!extensions/insights-default/**',
|
||||
'!extensions/json/**',
|
||||
'!extensions/json-language-features/**',
|
||||
'!extensions/markdown-basics/**',
|
||||
'!extensions/markdown-language-features/**',
|
||||
'!extensions/merge-conflict/**',
|
||||
'!extensions/powershell/**',
|
||||
'!extensions/python/**',
|
||||
'!extensions/r/**',
|
||||
'!extensions/theme-*/**',
|
||||
'!extensions/vscode-*/**',
|
||||
'!extensions/xml/**',
|
||||
'!extensions/xml-language-features/**',
|
||||
'!extensions/yarml/**',
|
||||
];
|
||||
|
||||
const tslintCoreFilter = [
|
||||
'src/**/*.ts',
|
||||
@@ -379,6 +405,7 @@ function hygiene(some) {
|
||||
input = some;
|
||||
}
|
||||
|
||||
// {{SQL CARBON EDIT}} Linting for SQL
|
||||
const tslintSqlConfiguration = tslint.Configuration.findConfiguration('tslint-sql.json', '.');
|
||||
const tslintSqlOptions = { fix: false, formatter: 'json' };
|
||||
const sqlTsLinter = new tslint.Linter(tslintSqlOptions);
|
||||
@@ -407,8 +434,8 @@ function hygiene(some) {
|
||||
if (!process.argv.some(arg => arg === '--skip-tslint')) {
|
||||
typescript = typescript.pipe(tsl);
|
||||
typescript = typescript
|
||||
.pipe(filter(sqlFilter))
|
||||
.pipe(sqlTsl); // {{SQL CARBON EDIT}}
|
||||
.pipe(filter(sqlFilter)) // {{SQL CARBON EDIT}}
|
||||
.pipe(sqlTsl);
|
||||
}
|
||||
|
||||
const javascript = result
|
||||
|
||||
@@ -48,9 +48,7 @@ class DoubleQuotedStringArgRuleWalker extends Lint.RuleWalker {
|
||||
const argText = arg.getText();
|
||||
const doubleQuotedArg = argText.length >= 2 && argText[0] === DoubleQuotedStringArgRuleWalker.DOUBLE_QUOTE && argText[argText.length - 1] === DoubleQuotedStringArgRuleWalker.DOUBLE_QUOTE;
|
||||
if (!doubleQuotedArg) {
|
||||
const fix = [
|
||||
Lint.Replacement.replaceFromTo(arg.getStart(), arg.getWidth(), `"${arg.getText().slice(1, arg.getWidth() - 2)}"`),
|
||||
];
|
||||
const fix = Lint.Replacement.replaceFromTo(arg.getStart(), arg.getEnd(), `"${arg.getText().slice(1, arg.getWidth() - 1)}"`);
|
||||
this.addFailure(this.createFailure(arg.getStart(), arg.getWidth(), `Argument ${this.argIndex + 1} to '${functionName}' must be double quoted.`, fix));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -68,9 +68,7 @@ class DoubleQuotedStringArgRuleWalker extends Lint.RuleWalker {
|
||||
const doubleQuotedArg = argText.length >= 2 && argText[0] === DoubleQuotedStringArgRuleWalker.DOUBLE_QUOTE && argText[argText.length - 1] === DoubleQuotedStringArgRuleWalker.DOUBLE_QUOTE;
|
||||
|
||||
if (!doubleQuotedArg) {
|
||||
const fix = [
|
||||
Lint.Replacement.replaceFromTo(arg.getStart(), arg.getWidth(), `"${arg.getText().slice(1, arg.getWidth() - 2)}"`),
|
||||
];
|
||||
const fix = Lint.Replacement.replaceFromTo(arg.getStart(), arg.getEnd(), `"${arg.getText().slice(1, arg.getWidth() - 1)}"`);
|
||||
this.addFailure(this.createFailure(
|
||||
arg.getStart(), arg.getWidth(),
|
||||
`Argument ${this.argIndex! + 1} to '${functionName}' must be double quoted.`, fix));
|
||||
|
||||
49
build/lib/tslint/noUnderscoreInLocalizeKeysRule.js
Normal file
49
build/lib/tslint/noUnderscoreInLocalizeKeysRule.js
Normal file
@@ -0,0 +1,49 @@
|
||||
"use strict";
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const ts = require("typescript");
|
||||
const Lint = require("tslint");
|
||||
/**
|
||||
* Implementation of the no-localize-keys-with-underscore rule which verifies that keys to the localize
|
||||
* calls don't contain underscores (_) since those break the localization process.
|
||||
*/
|
||||
class Rule extends Lint.Rules.AbstractRule {
|
||||
apply(sourceFile) {
|
||||
return this.applyWithWalker(new NoLocalizeKeysWithUnderscore(sourceFile, this.getOptions()));
|
||||
}
|
||||
}
|
||||
exports.Rule = Rule;
|
||||
const signatures = [
|
||||
"localize",
|
||||
"nls.localize"
|
||||
];
|
||||
class NoLocalizeKeysWithUnderscore extends Lint.RuleWalker {
|
||||
constructor(file, opts) {
|
||||
super(file, opts);
|
||||
}
|
||||
visitCallExpression(node) {
|
||||
this.checkCallExpression(node);
|
||||
super.visitCallExpression(node);
|
||||
}
|
||||
checkCallExpression(node) {
|
||||
// If this isn't one of the localize functions then continue on
|
||||
const functionName = node.expression.getText();
|
||||
if (functionName && !signatures.some(s => s === functionName)) {
|
||||
return;
|
||||
}
|
||||
const arg = node && node.arguments && node.arguments.length > 0 ? node.arguments[0] : undefined; // The key is the first element
|
||||
// Ignore if the arg isn't a string - we expect the compiler to warn if that's an issue
|
||||
if (arg && ts.isStringLiteral(arg)) {
|
||||
if (arg.getText().indexOf('_') >= 0) {
|
||||
const fix = [
|
||||
Lint.Replacement.replaceFromTo(arg.getStart(), arg.getEnd(), `${arg.getText().replace(/_/g, '.')}`),
|
||||
];
|
||||
this.addFailure(this.createFailure(arg.getStart(), arg.getWidth(), `Keys for localize calls must not contain underscores. Use periods (.) instead.`, fix));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
55
build/lib/tslint/noUnderscoreInLocalizeKeysRule.ts
Normal file
55
build/lib/tslint/noUnderscoreInLocalizeKeysRule.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as ts from 'typescript';
|
||||
import * as Lint from 'tslint';
|
||||
|
||||
/**
|
||||
* Implementation of the no-localize-keys-with-underscore rule which verifies that keys to the localize
|
||||
* calls don't contain underscores (_) since those break the localization process.
|
||||
*/
|
||||
export class Rule extends Lint.Rules.AbstractRule {
|
||||
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
|
||||
return this.applyWithWalker(new NoLocalizeKeysWithUnderscore(sourceFile, this.getOptions()));
|
||||
}
|
||||
}
|
||||
|
||||
const signatures = [
|
||||
"localize",
|
||||
"nls.localize"
|
||||
];
|
||||
|
||||
class NoLocalizeKeysWithUnderscore extends Lint.RuleWalker {
|
||||
|
||||
constructor(file: ts.SourceFile, opts: Lint.IOptions) {
|
||||
super(file, opts);
|
||||
}
|
||||
|
||||
protected visitCallExpression(node: ts.CallExpression): void {
|
||||
this.checkCallExpression(node);
|
||||
super.visitCallExpression(node);
|
||||
}
|
||||
|
||||
private checkCallExpression(node: ts.CallExpression): void {
|
||||
// If this isn't one of the localize functions then continue on
|
||||
const functionName = node.expression.getText();
|
||||
if (functionName && !signatures.some(s => s === functionName)) {
|
||||
return;
|
||||
}
|
||||
const arg = node && node.arguments && node.arguments.length > 0 ? node.arguments[0] : undefined; // The key is the first element
|
||||
// Ignore if the arg isn't a string - we expect the compiler to warn if that's an issue
|
||||
if(arg && ts.isStringLiteral(arg)) {
|
||||
if (arg.getText().indexOf('_') >= 0) {
|
||||
const fix = [
|
||||
Lint.Replacement.replaceFromTo(arg.getStart(), arg.getEnd(), `${arg.getText().replace(/_/g, '.')}`),
|
||||
];
|
||||
this.addFailure(this.createFailure(
|
||||
arg.getStart(), arg.getWidth(),
|
||||
`Keys for localize calls must not contain underscores. Use periods (.) instead.`, fix));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user