maverickpuss

.eslintrc

Feb 27th, 2020
635
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 8.28 KB | None | 0 0
  1. {
  2.   root: true,
  3.  
  4.   parserOptions: {
  5.     // use babel-eslint for ES6
  6.     parser: "babel-eslint",
  7.     ecmaVersion: 6,
  8.     sourceType: "module",
  9.     ecmaFeatures: {
  10.       jsx: false,
  11.       modules: true
  12.     }
  13.   },
  14.  
  15.   env: {
  16.     es6: true,
  17.     node: true,
  18.     browser: true
  19.   },
  20.  
  21.   // global variables that should bypass checking, share the same value as
  22.   // the `externals` field of webpack config
  23.   // p.s. different app uses different globals
  24.   globals: {
  25.     PAGE_PAYLOAD: true,
  26.     CONFIG: true
  27.   },
  28.  
  29.   extends: [
  30.     "eslint:recommended",
  31.     "plugin:prettier/recommended",
  32.     "plugin:vue/recommended"
  33.   ],
  34.  
  35.   rules: {
  36.     // us strictly equal operator
  37.     eqeqeq: "error",
  38.  
  39.     // line breaks should follow the operators, e.g. the && operator used
  40.     // inside multiple conditions should be put at the end of the previous line
  41.     "operator-linebreak": [
  42.       "error",
  43.       "after",
  44.       {
  45.         // ternary operators should be placed at the beginning of the line
  46.         overrides: {
  47.           "?": "ignore",
  48.           ":": "ignore"
  49.         }
  50.       }
  51.     ],
  52.  
  53.     // code blocks must be enclosed by curly brackets
  54.     curly: "error",
  55.  
  56.     // indent chained operations
  57.     "newline-per-chained-call": "error",
  58.  
  59.     // key-value pairs inside an object should be put into separated lines
  60.     "object-property-newline": [
  61.       "error",
  62.       {
  63.         // all properties in the same line is not allowed
  64.         allowAllPropertiesOnSameLine: false
  65.       }
  66.     ],
  67.  
  68.     // add line breaks for all properties if there is a property has line
  69.     // break, otherwise keep all of them in the same line
  70.     "object-curly-newline": [
  71.       "error",
  72.       {
  73.         // 对象申明的花括号,如果不换就都不换,如果换都换,只有一个键值对就不换,为空不换
  74.         // 只有一个键值对,但是导致本行超长,就要换(比如函数最后一个对象参数里面的键
  75.         // 是一个超长字符串)
  76.         ObjectExpression: { consistent: true },
  77.         // 赋值解构,要换都换,否则不换
  78.         ObjectPattern: { multiline: true },
  79.         // import 语句,两个及以上就要换
  80.         ImportDeclaration: { consistent: true },
  81.         // export 语句,要换都换,要不换都不换,如果不换导致本行超长,则全部换
  82.         ExportDeclaration: { consistent: true }
  83.       }
  84.     ],
  85.  
  86.     // always use double quotes
  87.     quotes: [
  88.       "error",
  89.       "double",
  90.       {
  91.         // do not escape double quotes which are inside single quote pairs,
  92.         // the same rule applys to single quotes
  93.         avoidEscape: true,
  94.         // allow template literals
  95.         allowTemplateLiterals: true
  96.       }
  97.     ],
  98.  
  99.     // only wrap up object keys inside quotes when it's necessary
  100.     // note that if we don't explicitly config this rule the vue eslint plugin
  101.     // will simply ignore it.
  102.     "quote-props": ["error", "as-needed"],
  103.  
  104.     // disable inline comments
  105.     "no-inline-comments": ["error"],
  106.  
  107.     // the opening curly bracket of a code block should stay in the end of the
  108.     // first line
  109.     "brace-style": [2, "1tbs"],
  110.  
  111.     // remove blank lines at the beginning and the end of a block
  112.     "padded-blocks": ["error", "never"],
  113.  
  114.     // line breaks inside code blocks
  115.     "padding-line-between-statements": [
  116.       "error",
  117.  
  118.       // break line before `if`
  119.       {
  120.         blankLine: "always",
  121.         prev: "*",
  122.         next: "if"
  123.       },
  124.       // break line before `for`
  125.       {
  126.         blankLine: "always",
  127.         prev: "*",
  128.         next: "for"
  129.       },
  130.       // break line before `return`
  131.       {
  132.         blankLine: "always",
  133.         prev: "*",
  134.         next: "return"
  135.       },
  136.       // break line before `function`
  137.       {
  138.         blankLine: "always",
  139.         prev: "*",
  140.         next: "function"
  141.       }
  142.     ],
  143.  
  144.     // no space before function opening parenthesis
  145.     "space-before-function-paren": ["error", "never"],
  146.  
  147.     // no space between it's name and the parenthesis pairs while calling
  148.     // a function
  149.     "func-call-spacing": ["error", "never"],
  150.  
  151.     // start comments with white spaces, either single line or multi-line
  152.     // comments
  153.     "spaced-comment": ["error", "always"],
  154.  
  155.     "arrow-spacing": ["error"],
  156.  
  157.     // force using semicolons to end a line
  158.     semi: ["error", "always"],
  159.  
  160.     // do not put white spaces before a semicolon, but there must be white
  161.     // spaces after it.
  162.     "semi-spacing": [
  163.       "error",
  164.       {
  165.         before: false,
  166.         after: true
  167.       }
  168.     ],
  169.  
  170.     // put white spaces before a code block
  171.     "space-before-blocks": ["error"],
  172.  
  173.     // there must be white spaces around an operator like `+`
  174.     "space-infix-ops": ["error"],
  175.  
  176.     // disallow white spaces before colons, but there must be white spaces
  177.     // after it. e.g. var a = 3, b = 4;
  178.     "comma-spacing": [
  179.       "error",
  180.       {
  181.         before: false,
  182.         after: true
  183.       }
  184.     ],
  185.  
  186.     // disallow multiple white spaces. e.g. let    a =  33;
  187.     "no-multi-spaces": ["error"],
  188.  
  189.     // put white spaces around keywords. e.g. if (xxx)
  190.     "keyword-spacing": [
  191.       "error",
  192.       {
  193.         before: true,
  194.         after: true
  195.       }
  196.     ],
  197.  
  198.     // disallow trailing commas, including: array/object/export/import/function
  199.     "comma-dangle": [
  200.       "error",
  201.       {
  202.         // after the last argument of a function there shouldn't be commas
  203.         functions: "never"
  204.       }
  205.     ],
  206.  
  207.     // put white spaces after object keys
  208.     "key-spacing": ["error", { afterColon: true }],
  209.  
  210.     // maximum line length up to 80 characters
  211.     "max-len": [
  212.       "error",
  213.       {
  214.         code: 80,
  215.         // ignore tempelate literals that exceeds the limit
  216.         ignoreTemplateLiterals: true,
  217.         // ignore regexp literals
  218.         ignoreRegExpLiterals: true,
  219.         // ignore urls
  220.         ignoreUrls: true,
  221.         // ignore import states
  222.         ignorePattern: "^\\s*import\\s+.+\\s+from\\s+.+;$"
  223.       }
  224.     ],
  225.  
  226.     // break lines for every argument of a function simultaneously if one
  227.     // of them has line break.
  228.     "function-paren-newline": ["error", "consistent"],
  229.  
  230.     // line breaks inside templates
  231.     // this conflicts with prettier!
  232.     "vue/max-attributes-per-line": [
  233.       2,
  234.       {
  235.         singleline: 1,
  236.         multiline: {
  237.           max: 1,
  238.           // 第一个属性不用换行:必须换行(目前和 prettier 冲突,prettier 会强制
  239.           // 换行)
  240.           allowFirstLine: false
  241.         }
  242.       }
  243.     ],
  244.  
  245.     // enforce self closing on tags
  246.     "vue/html-self-closing": [
  247.       "error",
  248.       {
  249.         html: {
  250.           // `img` and the like should close in `/>`
  251.           void: "always",
  252.           // never self-close a non-self-closing element like `<p>`
  253.           normal: "never",
  254.           component: "never"
  255.         },
  256.         svg: "never",
  257.         math: "never"
  258.       }
  259.     ],
  260.  
  261.     // use `camalCase` for props inside templates
  262.     "vue/attribute-hyphenation": [
  263.       2,
  264.       "never",
  265.       {
  266.         // exception: custom-prop: customized non-props properties
  267.         // e.g. abc-def="777"
  268.         ignore: ["data-", "aria-", "custom-prop"]
  269.       }
  270.     ],
  271.  
  272.     // component name should use lower case and `kebab-case`
  273.     "vue/name-property-casing": ["error", "kebab-case"]
  274.   },
  275.  
  276.   // add exception rules
  277.   overrides: [
  278.     {
  279.       files: ["*.vue"],
  280.       rules: {
  281.         // let prettier handle the "formatting" related tasks, while
  282.         // eslint should be limited to do only static analysis related tasks
  283.         // like syntax checking and fixing
  284.         indent: "off",
  285.         "vue/script-indent": "off",
  286.         "vue/html-indent": "off",
  287.         "vue/singleline-html-element-content-newline": "off"
  288.       }
  289.     },
  290.  
  291.     // `console` can be used inside NodeJS scripts
  292.     {
  293.       files: ["arch/**/*.js", "apps/*/utils/**/*.js"],
  294.       rules: {
  295.         "no-console": 0
  296.       }
  297.     },
  298.  
  299.     // mocha unit tests and global variables
  300.     {
  301.       files: ["apps/*/test/**/*.spec.js"],
  302.       globals: {
  303.         // ignore the global functions used by mocha
  304.         describe: true,
  305.         before: true,
  306.         after: true,
  307.         beforeEach: true,
  308.         afterEach: true,
  309.         it: true
  310.       }
  311.     }
  312.   ]
  313. }
Add Comment
Please, Sign In to add comment