Skip to content

Commit

Permalink
chore: release 1.0.0
Browse files Browse the repository at this point in the history
* chore: 升级过期依赖

* chore: remove tmp

* 1.0.0-0

* chore: add prettier

* fix: lint config

* chore: add ts example

* 1.0.0-1

* fix: rules

* 1.0.0-2

* fix: rule

* 1.0.0-3

* chore: lint

* 1.0.0

* fix: ts allow empty function

* 1.0.1

* chore: remove issue template
  • Loading branch information
imsobear authored Feb 19, 2020
1 parent ef9c89a commit d258c53
Show file tree
Hide file tree
Showing 17 changed files with 232 additions and 91 deletions.
4 changes: 1 addition & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
const { eslint, deepmerge } = require('./lib');

const eslintConfig = deepmerge(eslint, {
module.exports = deepmerge(eslint, {
env: {
jest: true
}
});

module.exports = eslintConfig;

This file was deleted.

3 changes: 3 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { prettier } = require('./lib');

module.exports = prettier;
4 changes: 4 additions & 0 deletions .stylelintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const { stylelint, deepmerge } = require('./lib');

module.exports = deepmerge(stylelint, {
});
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Easy to use eslint/stylelint/prettier. And spec means specification.
- [x] stylelint
- [x] eslint support TypeScript
- [x] commitlint
- [ ] prettier
- [x] prettier

## Install

Expand Down Expand Up @@ -42,14 +42,24 @@ module.exports = tslint;

### stylelint [rules](/lib/eslint.js)

in `.stylelint.js`
in `.stylelintrc.js`

```js
const { stylelint } = require('@ice/spec');

module.exports = stylelint;
```

### prettier [rules](/lib/prettier.js)

in `.prettierrc.js`

```js
const { prettier } = require('@ice/spec');

module.exports = prettier;
```

### commitlint [rules](https://github.com/conventional-changelog/commitlint/tree/master/@commitlint/config-conventional)

in `.commitlintrc.js`
Expand Down Expand Up @@ -77,3 +87,7 @@ module.exports = deepmerge(eslint, {
### Error: Cannot find module 'eslint-plugin-foo'

Eslint is not yet supported having plugins as dependencies in shareable config. [issue](https://github.com/eslint/eslint/issues/3458). As a temporary solution, you need add the plugin to devDependencies in your project, like `npm i --save-dev eslint-plugin-jsx-a11y`.

### Warning: incorrect peer dependency "eslint-plugin-react-hooks@^1.7.0"

[issue](https://github.com/airbnb/javascript/issues/2084)
10 changes: 10 additions & 0 deletions examples/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.a {
position: relative;
font-size: 12px;

/* color: 2; */
}

.b {
font-display: x;
}
37 changes: 37 additions & 0 deletions examples/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const foo = 1;
function bar() {}
function baz() {}

module.exports = () => {
console.log(111);
console.log(111);
console.log(111);
console.log(111);
console.log(111);
console.log(111);
console.log(111);
console.log(111);
console.log(111);
console.log(111);
console.log(111);
console.log(111);
const a = 'sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss';
console.log(111, a);
console.log(222);

const b = {
'a': 1,
'b': 1,
};
const c = 'xxxx';
console.log(b);

if (foo) {
bar();
}

if (foo) {
bar();
baz();
}
};
31 changes: 31 additions & 0 deletions examples/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React, { useState } from 'react';

let actions;

function A() {
const a = 1;
switch (a) {
case 1:
actions = (
<div>
下一步
</div>
);
break;
case 0:
break;
default:
break;
}
return (
<React.Fragment></React.Fragment>
)
}

const a = actions ? {
c: 1,
} : { d: 2 };
const g = actions
? {
c: 1,
} : { d: 2 };
7 changes: 7 additions & 0 deletions examples/ts/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const { tslint, deepmerge } = require('../../lib');

module.exports = deepmerge(tslint, {
env: {
jest: true
}
});
8 changes: 8 additions & 0 deletions examples/ts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const a = 1;

export default () => {
const b = 2;
}


function add() {}
19 changes: 19 additions & 0 deletions examples/ts/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';

let actions;
function A() {
switch (true) {
case true:
actions = (
<div>
下一步
</div>
);
break;
default:
break;
}
return (
<React.Fragment></React.Fragment>
)
}
101 changes: 57 additions & 44 deletions lib/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ module.exports = {
},
extends: [
/** Airbnb JavaScript Style Guide https://github.com/airbnb/javascript#types */
// Airbnb include react, react-a11y(include jsx-a11y)
// dep plugins: plugin-react, plugin-jsx-a11y
// include rules: airbnb-base, custom react, custom react-a11y
require.resolve('eslint-config-airbnb'),

require.resolve('eslint-config-prettier'),
require.resolve('eslint-config-prettier/react'),
],
Expand All @@ -24,93 +26,104 @@ module.exports = {
},
rules: {
/** React Hooks Style Guide https://reactjs.org/docs/hooks-rules.html */
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',

/** 无障碍相关 https://github.com/evcohen/eslint-plugin-jsx-a11y/tree/master/docs/rules */
// label htmlFor 属性或者用 label 把表单组件包起来:警告
"jsx-a11y/label-has-associated-control": 1,
'jsx-a11y/label-has-associated-control': 1,
// 静态元素(div/span/...)不允许绑定事件,除非指定 role:取消
"jsx-a11y/no-static-element-interactions": 0,
'jsx-a11y/no-static-element-interactions': 0,
// 静态元素(div/span/...)不允许绑定事件,除非指定 role:取消
"jsx-a11y/no-noninteractive-element-interactions": 0,
'jsx-a11y/no-noninteractive-element-interactions': 0,
// 支持 click 事件必须同时支持键盘事件:取消
"jsx-a11y/click-events-have-key-events": 0,
'jsx-a11y/click-events-have-key-events': 0,
// 禁止不规则使用 a 标签:取消
"jsx-a11y/anchor-is-valid": 0,
'jsx-a11y/anchor-is-valid': 0,
// require that JSX labels use "htmlFor": 警告
"jsx-a11y/label-has-for": 1,
'jsx-a11y/label-has-for': 1,

/** react相关 https://github.com/yannickcr/eslint-plugin-react/tree/master/docs/rules */
// index 不能作为 key:取消
"react/no-array-index-key": 0,
'react/no-array-index-key': 0,
// 每行只能有一个jsx组件声明: 取消
"react/jsx-one-expression-per-line": 0,
'react/jsx-one-expression-per-line': 0,
// 必须声明 propTypes:取消
"react/prop-types": 0,
'react/prop-types': 0,
// 第一个props必须放在新的一行:取消 TBD
"react/jsx-first-prop-new-line": 0,
'react/jsx-first-prop-new-line': 0,
// 使用 props/state/context 必须解构:取消
"react/destructuring-assignment": 0,
'react/destructuring-assignment': 0,
// 禁止不具体的 propTypes 声明:取消
"react/forbid-prop-types": 0,
"react/jsx-filename-extension": [
'react/forbid-prop-types': 0,
'react/jsx-filename-extension': [
1,
{
"extensions": [".js", ".jsx"],
'extensions': ['.js', '.jsx'],
},
],
// 允许使用 React.Fragment
'react/jsx-fragments': 0,
// ...props
'react/jsx-props-no-spreading': 0,

// 不允许使用 dangerous 属性:取消
"react/no-danger": 0,
'react/no-danger': 0,

/** import/export相关 https://github.com/benmosher/eslint-plugin-import/tree/master/docs/rules */
// 必须写明文件类型:取消
"import/extensions": 0,
'import/extensions': 0,
// 路径必须可以被本地文件系统解析:取消
"import/no-unresolved": 0,
'import/no-unresolved': 0,
// 只能引用package.json声明的依赖:取消 TBD
"import/no-extraneous-dependencies": 0,
'import/no-extraneous-dependencies': 0,
// 优先使用 export default: 取消
"import/prefer-default-export": 0,
'import/prefer-default-export': 0,

/** 基础语法规则 https://eslint.org/docs/rules/ */
// 禁止 console.log:取消
"no-console": 0,
'no-console': 0,
// 禁止变量声明与外层作用域的变量同名:警告
"no-shadow": 1,
'no-shadow': 1,
// 禁止未使用过的表达式:警告
"no-unused-expressions": 1,
'no-unused-expressions': 1,
// 禁止变量定义前使用:警告, 函数除外
"no-use-before-define": ["warn", { "functions": false }],
'no-use-before-define': ['warn', { 'functions': false }],
// 禁止直接调用 Object.prototypes 的内置属性:警告
"no-prototype-builtins": 1,
'no-prototype-builtins': 1,
// 禁止匿名函数:取消
"func-names": 0,
'func-names': 0,
// 箭头函数必须使用大括号:取消
"arrow-body-style": 0,
'arrow-body-style': 0,
// 优先使用解构:取消
"prefer-destructuring": 0,
'prefer-destructuring': 0,
// 禁止对函数参数进行重新赋值:警告
"no-param-reassign": 1,
// 强制一行的最大长度:取消
"max-len": 0,
'no-param-reassign': 1,
// 函数必须有返回值:取消 TBD
"consistent-return": 0,
// 拖尾逗号:多行时必须每行有逗号
"comma-dangle": ["error", "always-multiline"],
'consistent-return': 0,
// 对象声明是否换行:取消
"object-curly-newline": 0,
'object-curly-newline': 0,
// 禁用特定的全局变量:取消
"no-restricted-globals": 0,
'no-restricted-globals': 0,
// 禁止 if 语句中 return 语句之后有 else 块:取消
"no-else-return": 0,
'no-else-return': 0,
// 禁止在 return 语句中使用赋值语句:取消 TBD ref={formRef => form = formRef}
"no-return-assign": 0,
'no-return-assign': 0,
// 禁止在return语句中使用await:取消
"no-return-await": 0,
'no-return-await': 0,
// 禁止 ++ --: 取消
"no-plusplus": 0,
// 强制语句结尾必须加逗号:开启
"semi": ["error", "always"],
'no-plusplus': 0,

// 分号结尾:不要求
'semi': 0,
// 结尾逗号:不要求
'comma-dangle': 0,
// 声明未使用:warning
'no-unused-vars': 1,
// 缩进:强制两空格
'indent': ['error', 2, { 'SwitchCase': 1, 'flatTernaryExpressions': true, }],
// 强制一行的最大长度:不限制
'max-len': 0,
'quotes': ['error', 'single'],
},
};
3 changes: 3 additions & 0 deletions lib/prettier.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
singleQuote: true
};
14 changes: 7 additions & 7 deletions lib/stylelint.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
module.exports = {
extends: [
require.resolve("stylelint-config-standard"),
require.resolve("stylelint-config-css-modules"),
require.resolve("stylelint-scss"),
require.resolve("stylelint-config-rational-order"),
require.resolve("stylelint-config-prettier"),
require.resolve('stylelint-config-standard'),
require.resolve('stylelint-config-css-modules'),
require.resolve('stylelint-scss'),
require.resolve('stylelint-config-rational-order'),
require.resolve('stylelint-config-prettier'),
],
plugins: [
"stylelint-order",
'stylelint-order',
],
rules: {
"no-empty-source": null,
'no-empty-source': null,
},
};
Loading

0 comments on commit d258c53

Please sign in to comment.