この文章は Salesforce 機械翻訳システムを使用して翻訳されました。詳細はこちらをご参照ください。
英語に切り替える

独自のカスタムルール

Salesforce Lightning CLI がコードに適用する JavaScript スタイルルールをカスタマイズできます。

組織やプロジェクトが異なれば、採用される JavaScript ルールも異なることはよくあります。Lightning CLI ツールを使用すると、Salesforce コーディング規則を強制せずに、LockerService に対応できるようになります。そのために、Lightning CLI ルールは、セキュリティルールとスタイルルールの 2 つのセットに分かれています。セキュリティルールは変更できませんが、スタイルルールの変更や追加はできます。

カスタムルール設定ファイルを指定するには、--config 引数を使用します。カスタムルール設定ファイルを使用すると、独自のコードスタイルルールを定義し、Lightning CLI ツールで使用されるスタイルルールに反映させることができます。

Lightning CLI のデフォルトのスタイルルールは下記を参照してください。このルールを新しいファイルにコピーし、目的のスタイルルールに合わせて変更します。または、既存の ESLint ルール設定ファイルを直接使用してください。以下に例を示します。
1heroku lightning:lint ./path/to/lightning/components/ --config ~/.eslintrc

--config を使用した追加や変更ができない ESLint ルールもあります。Lightning プラットフォームのコンテキストで安全または中立と見なされたルールのみが、Lightning CLI で有効化されます。セキュリティルールは上書きできません。

メモ

デフォルトのスタイルルール

次に、Lightning CLI で使用されるデフォルトのスタイルルールを示します。

1/*
2 * Copyright (C) 2016 salesforce.com, inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *         http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 module.exports = {
18    rules: {
19        // code style rules, these are the default value, but the user can
20        // customize them via --config in the linter by providing custom values
21        // for each of these rules.
22        "no-trailing-spaces": 1,
23        "no-spaced-func": 1,
24        "no-mixed-spaces-and-tabs": 0,
25        "no-multi-spaces": 0,
26        "no-multiple-empty-lines": 0,
27        "no-lone-blocks": 1,
28        "no-lonely-if": 1,
29        "no-inline-comments": 0,
30        "no-extra-parens": 0,
31        "no-extra-semi": 1,
32        "no-warning-comments": [0, { "terms": ["todo", "fixme", "xxx"], "location": "start" }],
33        "block-scoped-var": 1,
34        "brace-style": [1, "1tbs"],
35        "camelcase": 1,
36        "comma-dangle": [1, "never"],
37        "comma-spacing": 1,
38        "comma-style": 1,
39        "complexity": [0, 11],
40        "consistent-this": [0, "that"],
41        "curly": [1, "all"],
42        "eol-last": 0,
43        "func-names": 0,
44        "func-style": [0, "declaration"],
45        "generator-star-spacing": 0,
46        "indent": 0,
47        "key-spacing": 0,
48        "keyword-spacing": [0, "always"],
49        "max-depth": [0, 4],
50        "max-len": [0, 80, 4],
51        "max-nested-callbacks": [0, 2],
52        "max-params": [0, 3],
53        "max-statements": [0, 10],
54        "new-cap": 0,
55        "newline-after-var": 0,
56        "one-var": [0, "never"],
57        "operator-assignment": [0, "always"],
58        "padded-blocks": 0,
59        "quote-props": 0,
60        "quotes": 0,
61        "semi": 1,
62        "semi-spacing": [0, {"before": false, "after": true}],
63        "sort-vars": 0,
64        "space-after-function-name": [0, "never"],
65        "space-before-blocks": [0, "always"],
66        "space-before-function-paren": [0, "always"],
67        "space-before-function-parentheses": [0, "always"],
68        "space-in-brackets": [0, "never"],
69        "space-in-parens": [0, "never"],
70        "space-infix-ops": 0,
71        "space-unary-ops": [1, { "words": true, "nonwords": false }],
72        "spaced-comment": [0, "always"],
73        "vars-on-top": 0,
74        "valid-jsdoc": 0,
75        "wrap-regex": 0,
76        "yoda": [1, "never"]
77    }
78};