我正在用Ionic2/Cordova/Typescript/Angular做一个测试应用程序.我正在使用tslint 5.6.0.
我正在使用以下模块:https: //www.npmjs.com/package/tslint
专注于一个文件......
当linting以下文件时:
import { NgModule, ErrorHandler } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { IonicApp, IonicModule, IonicErrorHandler } from "ionic-angular";
import { MyApp } from "./app.component";
import { AboutPage } from "../pages/about/about";
import { ContactPage } from "../pages/contact/contact";
import { HomePage } from "../pages/home/home";
import { TabsPage } from "../pages/tabs/tabs";
import { StatusBar } from "@ionic-native/status-bar";
import { SplashScreen } from "@ionic-native/splash-screen";
@NgModule( {
declarations: [
MyApp,
AboutPage,
ContactPage, …
Run Code Online (Sandbox Code Playgroud) 我在我的项目中收到以下TsLint消息:
TsLint:注释必须以小写字母开头
这背后有什么基础吗?我同意我在TsLint中遇到的大部分内容,并且我知道能够关闭此警告.
我宁愿理解为什么他们建议这个特殊的规则.我在https://github.com/palantir/tslint#supported-rules上阅读了这些文档,它们解释了规则的作用但不解释原因.
请考虑以下代码段.我需要在typescript中设置多个CSS属性.为此,我尝试了以下代码.
public static setStyleAttribute(element: HTMLElement, attrs: { [key: string]: Object }): void {
if (attrs !== undefined) {
Object.keys(attrs).forEach((key: string) => {
element.style[key] = attrs[key];
});
}
}
Run Code Online (Sandbox Code Playgroud)
对于上面的代码,我需要传递参数为
let elem: HTMLElement = document.getElementById('myDiv');
setStyleAttribute(elem, {font-size:'12px', color : 'red' , margin-top: '5px'});
Run Code Online (Sandbox Code Playgroud)
但是上面的代码抛出错误(tslint),因为Element隐式具有'any'类型,因为索引表达式不是'number'类型.(属性)HTMLElement.style:CSSStyleDeclaration.
请帮我 !!!
tslint当前引发以下错误
Shadowed name: 'err'
Run Code Online (Sandbox Code Playgroud)
这是代码
fs.readdir(fileUrl, (err, files) => {
fs.readFile(path.join(fileUrl, files[0]), function (err, data) {
if (!err) {
res.send(data);
}
});
});
Run Code Online (Sandbox Code Playgroud)
任何人都知道最好的解决方法是什么,错误甚至意味着什么?
我在 Stackoverflow 和网络上搜索,我发现这个线程https://github.com/Microsoft/TypeScript/issues/14813但它没有解决我的问题。我在编译我的代码时遇到了这个错误ng serve --watch
。
错误 TS2339:“FormData”类型上不存在属性“entries”。
这部分fd.entries()
触发了错误......知道这里发生了什么吗?
onFileSelected(event) {
const fd = new FormData;
for (const file of event.target.files) {
fd.append('thumbnail', file, file.name);
const entries = fd.entries();
// some other methods are called here e. g. upload the images
for (const pair of entries) {
fd.delete(pair[0]);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我看到那里(https://github.com/Microsoft/TypeScript/blob/master/src/lib/dom.iterable.d.ts)是一些接口,entries
但不知何故这对我不起作用。
编辑
我的tsconfig.json
看起来像这样
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true, …
Run Code Online (Sandbox Code Playgroud) 我无法弄清楚为什么我tslint
甚至想在最后一行的末尾看到尾随的逗号objects
?例如,如何ignore
为对象的最后一行设置规则?谢谢.
例:
props = {
prop1: 21, // good
prop2: 2, // good
prop3: false // error: [tslint] Missing trailing comma (trailing-comma)
}
Run Code Online (Sandbox Code Playgroud)
trailing-comma
我的规则tsconfig.json
:
"trailing-comma": [true, {
"singleline": "never",
"multiline": {
"objects": "always",
"arrays": "always",
"functions": "never",
"typeLiterals": "ignore"
}
}]
Run Code Online (Sandbox Code Playgroud) 我在 Visual Studio Code 中使用带有 TSLint 和 Prettier 的 TypeScript 来编写 React Native 应用程序。
我试图将我的编辑器配置为将每行代码自动包装为 100 个字符。但保存后总是 80 个字符,而不是 100 个。
以下是我更改的设置:
"prettier.tslintIntegration": true,
"prettier.printWidth": 100,
"editor.renderIndentGuides": true,
"editor.rulers": [100],
"editor.wordWrapColumn": 100,
"editor.formatOnSave": true
Run Code Online (Sandbox Code Playgroud)
这是我的tslint.json
:
{
"extends": ["tslint:recommended", "tslint-react", "tslint-config-prettier"],
"rules": {
// "jsx-no-lambda": false,
"member-access": false,
"interface-name": false,
"max-line-length": [true, 100]
}
}
Run Code Online (Sandbox Code Playgroud)
即使我以这种方式配置了所有内容,我的代码仍然会自动换行 80 个字符。我怎样才能让它停止?
如果我的行超过 100 个字符,我会收到 linting 错误,因此该tslint.json
设置似乎有效。
奖励:完成 VSCode 设置,以防我遗漏了什么:
{
"telemetry.enableTelemetry": false,
"workbench.colorTheme": "One Dark Pro",
"workbench.iconTheme": "vscode-icons",
"window.zoomLevel": 0, …
Run Code Online (Sandbox Code Playgroud) 我正在尝试配置我的 TSLint 规则ordered-imports
以使导入顺序如下所示:
// React
import React from 'react';
import { View } from 'react-native';
// Libs
import * as _ from 'lodash';
import * as moment from 'moment';
// Internal libs
import Bar from '@app/bar';
import Foo from '@app/foo';
// Relative paths
import { Element } from './my-element';
import MyFunction from './my-function';
Run Code Online (Sandbox Code Playgroud)
这是我试图创建的规则,但我仍然无法达到上述工作的程度。
我似乎无法匹配绝对导入以外react
的绝对导入,我尝试使用null
以及非反应匹配,^!react
但它不起作用。
这是我的规则
{
"ordered-imports": [
true,
{
"module-source-path": "full",
"grouped-imports": true,
"groups": [
{
"name": "react",
"match": "^react", …
Run Code Online (Sandbox Code Playgroud) 我希望我的 tslint 忽略分号。
我想遵守规则"extends": "tslint:recommended"
。现在,我只是不能遵循这个规则,这迫使我总是使用分号,或者使用另一个"semicolon": [true, "never"]
,这迫使我删除所有分号。我只想无视他们。我可以通过删除来做到这一点,"extends": "tslint:recommended"
但我想保留这个规则,只是忽略分号。
tslint 文档只是提供了始终保留或始终删除的选项,但不能忽略它们。
有人能帮我吗?
将 angular 从 9 升级到 10 并运行后npm run lint
,我得到了这个实验> ng lint --fix
Schema validation failed with the following errors:
Data path "" should NOT have additional properties(tsConfig).
Run Code Online (Sandbox Code Playgroud)
我的 angular.json 是:
..."lint": {
"builder": "@angular-eslint/builder:lint",
"options": {
"eslintConfig": ".eslintrc.js",
"tsConfig": [
"tsconfig.app.json",
"tsconfig.spec.json",
"e2e/tsconfig.json"
],
"exclude": ["**/node_modules/**"]
}
},...
Run Code Online (Sandbox Code Playgroud)
这是我的 package.json - devDependencies:
..."@angular-devkit/build-angular": "~0.1001.1",
"@angular-eslint/builder": "0.3.0-beta.1",
"@angular-eslint/eslint-plugin": "0.0.1-alpha.32",
"@angular-eslint/eslint-plugin-template": "0.0.1-alpha.32",
"@angular-eslint/template-parser": "0.0.1-alpha.32",
"@angular/cli": "~10.1.0",
"@angular/compiler-cli": "~10.1.1",
"@angular/language-service": "~10.1.1",
"@types/file-saver": "^2.0.1",
"@types/google-libphonenumber": "^7.4.19",
"@types/jasmine": "~3.3.8",
"@types/jasminewd2": "~2.0.3",
"@typescript-eslint/eslint-plugin": "2.31.0", …
Run Code Online (Sandbox Code Playgroud)