如何将 sass-lint 添加到我的 angular-cli.json 文件中?
Posted
技术标签:
【中文标题】如何将 sass-lint 添加到我的 angular-cli.json 文件中?【英文标题】:How do I add sass-lint to my angular-cli.json file? 【发布时间】:2017-10-02 11:10:22 【问题描述】:我正在使用这个种子应用程序:https://github.com/2sic/app-tutorial-angular4-hello-dnn
我已经安装了 sass-lint:https://www.npmjs.com/package/sass-lint
但不确定如何将其添加到我的 angular-cli.json 文件中。
在本示例中,我使用 angular version 4、webpack、typescript 和 sass。
我已使用默认设置将“sass-lint.yml”文件添加到我的根目录。
这是我的 angular-cli.json 文件:
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project":
"name": "my-app"
,
"apps": [
"root": "src",
"outDir": "dist",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"styles": [
"styles.scss"
],
"scripts": [
"../node_modules/lodash/lodash.js"
],
"environmentSource": "environments/environment.ts",
"environments":
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
],
"e2e":
"protractor":
"config": "./protractor.conf.js"
,
"lint": [
"project": "src/tsconfig.app.json"
,
"project": "src/tsconfig.spec.json"
,
"project": "e2e/tsconfig.e2e.json"
],
"test":
"karma":
"config": "./karma.conf.js"
,
"defaults":
"styleExt": "scss",
"component":
【问题讨论】:
【参考方案1】:这是我的解决方案:
1.包.json
"sass-lint": "./node_modules/sass-lint/bin/sass-lint.js -c src/sass-lint.yml -v -q",
"lint": "npm run saas-lint && ng lint",
2。 src/sass-lint.yml
files:
include: '**/src/**/*.s+(a|c)ss'
3.完成这些更改后,您可以在单个命令中运行所有 linting 规则
npm run lint
参考文件:
package.json
"name": "my-app",
"version": "0.0.0",
"license": "MIT",
"scripts":
"ng": "ng",
"start": "ng serve",
"build": "ng lint && ng build --prod",
"test": "ng test --browsers Chrome",
"sass-lint": "./node_modules/sass-lint/bin/sass-lint.js -c src/sass-lint.yml -v -q",
"lint": "npm run saas-lint && ng lint",
"e2e": "ng e2e",
"release": "npm run lint && ng test --watch=false --cc --browsers Chrome && ng build --prod",
"preflight": "npm run lint && ng test --watch=false --cc --browsers ChromeHeadless && ng build --prod"
,
"private": true,
"dependencies":
"@angular/animations": "^4.0.2",
"@angular/common": "^4.0.2",
"@angular/compiler": "^4.0.2",
"@angular/compiler-cli": "^4.0.0",
"@angular/core": "^4.0.2",
"@angular/forms": "^4.0.2",
"@angular/http": "^4.0.2",
"@angular/platform-browser": "^4.0.2",
"@angular/platform-browser-dynamic": "^4.0.2",
"@angular/platform-server": "^4.0.2",
"@angular/router": "^4.0.2",
"bootstrap": "^4.0.0-alpha.6",
"class-transformer": "^0.1.6",
"core-js": "^2.4.1",
"font-awesome": "^4.7.0",
"ng2-validation": "^4.1.0",
"ngx-clipboard": "^5.1.0",
"ngx-infinite-scroll": "^0.4.3",
"primeng": "^4.0.0",
"rxjs": "^5.3.0",
"typescript": "^2.2.1",
"zone.js": "^0.8.5"
,
"devDependencies":
"@angular/cli": "^1.0.3",
"@angular/compiler-cli": "^4.0.2",
"@types/jasmine": "^2.5.47",
"@types/node": "^7.0.15",
"codelyzer": "~3.0.1",
"grunt": "~0.4.5",
"grunt-contrib-jshint": "~0.10.0",
"grunt-contrib-nodeunit": "~0.4.1",
"grunt-contrib-uglify": "~0.5.0",
"grunt-karma-sonar": "~0.2.27",
"jasmine-core": "~2.5.2",
"jasmine-spec-reporter": "~3.3.0",
"karma": "^1.6.0",
"karma-chrome-launcher": "~2.0.0",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.1.0",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"karma-sonarqube-unit-reporter": "^0.0.11",
"node-sass": "^4.5.2",
"protractor": "~5.1.1",
"sass-lint": "^1.10.2",
"ts-node": "~3.0.2",
"tslint": "^5.2.0",
"typescript": "~2.2.2"
src/sass-lint.yml
options:
formatter: stylish
files:
include: '**/src/**/*.s+(a|c)ss'
rules:
# Extends
extends-before-mixins: 1
extends-before-declarations: 1
placeholder-in-extend: 1
# Mixins
mixins-before-declarations: 1
# Line Spacing
one-declaration-per-line: 1
empty-line-between-blocks: 1
single-line-per-selector: 1
# Disallows
no-attribute-selectors: 0
no-color-hex: 0
no-color-keywords: 1
no-color-literals: 1
no-combinators: 0
no-css-comments: 1
no-debug: 1
no-disallowed-properties: 0
no-duplicate-properties: 1
no-empty-rulesets: 1
no-extends: 0
no-ids: 1
no-important: 1
no-invalid-hex: 1
no-mergeable-selectors: 1
no-misspelled-properties: 1
no-qualifying-elements: 1
no-trailing-whitespace: 1
no-trailing-zero: 1
no-transition-all: 1
no-universal-selectors: 0
no-url-domains: 1
no-url-protocols: 1
no-vendor-prefixes: 1
no-warn: 1
property-units: 0
# Nesting
declarations-before-nesting: 1
force-attribute-nesting: 1
force-element-nesting: 1
force-pseudo-nesting: 1
# Name Formats
class-name-format: 1
function-name-format: 1
id-name-format: 0
mixin-name-format: 1
placeholder-name-format: 1
variable-name-format: 1
# Style Guide
attribute-quotes: 1
bem-depth: 0
border-zero: 1
brace-style: 1
clean-import-paths: 1
empty-args: 1
hex-length: 1
hex-notation: 1
indentation: 1
leading-zero: 1
max-line-length: 0
max-file-line-count: 0
nesting-depth: 1
property-sort-order: 1
pseudo-element: 1
quotes: 1
shorthand-values: 1
url-quotes: 1
variable-for-property: 1
zero-unit: 1
# Inner Spacing
space-after-comma: 1
space-before-colon: 1
space-after-colon: 1
space-before-brace: 1
space-before-bang: 1
space-after-bang: 1
space-between-parens: 1
space-around-operator: 1
# Final Items
trailing-semicolon: 1
final-newline: 1
【讨论】:
我只是建议在 node_modules 上添加 ignore: ignore: - 'node_modules/**/*.*' 在 'files' 部分 如果你保存文件,这个方法不会出错,所以必须记住运行 npm lint...你知道一种方法来挂钩 watch 事件,以便在你保存 SCSS 文件时运行它吗? 这行得通,但我不得不将我的脚本更改为以下"sass-lint -c sass-lint.yml -v -q"
如果你使用的是 VSCode,这个扩展非常适合在编辑器中强调违规行为:marketplace.visualstudio.com/items?itemName=glen-84.sass-lint
在第 1 步中还有一个错字。 npm run saas-lint
不应该是 npm run sass-lint
吗?以上是关于如何将 sass-lint 添加到我的 angular-cli.json 文件中?的主要内容,如果未能解决你的问题,请参考以下文章
如何删除 WebStorm sass-lint 错误“未知的伪选择器 'ng-deep'”
如何将 UIButtons 添加到我的 TableViewCell? [复制]