微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

tslint 在我的 TypeScript 项目中不起作用

如何解决tslint 在我的 TypeScript 项目中不起作用

我尝试在我的 ts 项目中添加一些 tslint 规则,但我发现它不起作用。例如:我添加了单引号规则,但是当我尝试使用双引号时,它编译成功。我的 tslint 是 6.1.3 版本,typescript 4.2.3 版本。为了您的信息,我将我的 package.json、tsconfig.json、tslint.json 和 webpack.config.js 文件粘贴在这里package.json:

  "name": "client-side","version": "1.0.0","description": "source of ts-learning","main": "./src/index.ts","scripts": {
    "test": "echo \"Error: no test specified\" && exit 1","start": "cross-env NODE_ENV=development webpack serve --mode development --env development --config ./build/webpack.config","build": "cross-env NODE_ENV=production webpack --mode production --env production --config ./build/webpack.config","lint": "tslint --project tsconfig.json"
  },"keywords": [
    "typescript","learning_test"
  ],"author": "Don","license": "MIT","devDependencies": {
    "clean-webpack-plugin": "^3.0.0","html-webpack-plugin": "^5.3.0","ts-loader": "^8.0.17","tslint": "^6.1.3","typescript": "^4.2.3","webpack": "^5.24.4","webpack-cli": "^4.5.0","webpack-dev-server": "^3.11.2"
  },"dependencies": {
    "cross-env": "^7.0.3"
  }
}

tsconfig.json:

{
  "compilerOptions": {
    "target": "es5",/* Specify ECMAScript target version: 'ES3' (default),'ES5','ES2015','ES2016','ES2017','ES2018','ES2019','ES2020',or 'ESNEXT'. */
    "module": "commonjs",/* Specify module code generation: 'none','commonjs','amd','system','umd','es2015','ES2020',or 'ESNext'. */
    "esModuleInterop": true,/* Enables emit interoperability between Commonjs and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
    "skipLibCheck": true,/* Skip type checking of declaration files. */
    "forceConsistentCasingInFileNames": true  /* disallow inconsistently-cased references to the same file. */
  }
}

tslint.json

{
    "defaultSeverity": "error","extends": [
        "tslint:recommended"
    ],"jsRules": {},"rules": {
        "quotemark": [
            true,"single"
        ]
    },"rulesDirectory": []
}

webpack.config.json

const HtmlWebpackPlugin = require('html-webpack-plugin')
const {CleanWebpackPlugin} = require('clean-webpack-plugin')
const path = require('path') 
module.exports = {
    entry: './src/index.ts',output: {
        filename: "main.js",path: path.resolve(__dirname,'dist'),},resolve: {
        extensions:['.ts','.tsx','.js']
    },module: {
        rules: [
            { test: /\.tsx?$/,use: 'ts-loader',exclude: /node_modules/ }
        ]
    },devtool: process.env.NODE_ENV === 'production' ? false : 'inline-source-map',devServer: {
        contentBase: './dist',stats: 'errors-only',compress: false,host: 'localhost',port: 8089
    },plugins: process.env.NODE_ENV === 'production' ? [
        new CleanWebpackPlugin(),new HtmlWebpackPlugin({
            template: './src/template/index.html'
        })] : [
            new HtmlWebpackPlugin({
                template: './src/template/index.html'
            })
        ]
}

抱歉发布了这么多代码,其中一些可能没用。但我真的希望有人能教我解决这个问题。谢谢你。最好的祝福。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。