Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat add prettier #40

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,22 @@ After that, you can add to your` package.json` the following code:

### Update from @ice/spec

If you are using [@ice/spce](https://www.npmjs.com/package/@ice/spec) in your project, we recommend use `@iceworks/spec` to get better maintainability and faster response to lint rules support.
If you are using [@ice/spec](https://www.npmjs.com/package/@ice/spec) in your project, we recommend use `@iceworks/spec` to get better maintainability and faster response to lint rules support.

Based on `@iceworks/spec`'s simple API you can quickly migrate your project, install and update your lint config file, the mission is completed 😁.

### Usage with Node.js API

If you are using spec rules in `CLIEngine` or `Linter`, Please set `cwd` to path of spec that can help ESLint find dependent plugins and configs.

```js
// CLIEngine
new CLIEngine({ cwd: path.dirname(require.resolve('@iceworks/spec')) });

// Linter
new Linter({ cwd: path.dirname(require.resolve('@iceworks/spec')) });
```

## Develop

### Run Test
Expand Down
25 changes: 13 additions & 12 deletions packages/eslint-plugin-best-practices/src/configs/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,23 @@ module.exports = {
},
},
{
files: [
'**/__tests__/*.{j,t}s?(x)',
'**/tests/*.{j,t}s?(x)',
'**/test/*.{j,t}s?(x)',
],
files: ['**/__tests__/*.{j,t}s?(x)', '**/tests/*.{j,t}s?(x)', '**/test/*.{j,t}s?(x)'],
env: { jest: true },
},
],
rules: {
'max-len': ['warn', 120, 2, {
ignoreUrls: true,
ignoreComments: false,
ignoreRegExpLiterals: true,
ignoreStrings: true,
ignoreTemplateLiterals: true,
}],
'max-len': [
'warn',
120,
2,
{
ignoreUrls: true,
ignoreComments: false,
ignoreRegExpLiterals: true,
ignoreStrings: true,
ignoreTemplateLiterals: true,
},
],
'@iceworks/best-practices/no-http-url': 'warn',
'@iceworks/best-practices/no-js-in-ts-project': 'warn',
'@iceworks/best-practices/no-lowercase-component-name': 'warn',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,7 @@ module.exports = {
dependencyVersion.indexOf('>') > -1
) {
let newVersioning = '^1.0.0';
const dependencyPackageFile = path.join(
cwd,
'node_modules',
dependencyName,
'package.json',
);
const dependencyPackageFile = path.join(cwd, 'node_modules', dependencyName, 'package.json');
if (fs.existsSync(dependencyPackageFile)) {
const dependencyPackage = fs.readJSONSync(dependencyPackageFile);
newVersioning = `^${dependencyPackage.version}`;
Expand Down
18 changes: 8 additions & 10 deletions packages/eslint-plugin-best-practices/src/rules/no-secret-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,18 @@ module.exports = {
return {
Literal: function handleRequires(node) {
if (
node.value && node.parent && (
// var secret = 'test';
(node.parent.type === 'VariableDeclarator' &&
node.parent.id &&
node.parent.id.name &&
reg.test(node.parent.id.name.toLocaleLowerCase())
) ||
node.value &&
node.parent &&
// var secret = 'test';
((node.parent.type === 'VariableDeclarator' &&
node.parent.id &&
node.parent.id.name &&
reg.test(node.parent.id.name.toLocaleLowerCase())) ||
// { secret: 'test' };
(node.parent.type === 'Property' &&
node.parent.key &&
node.parent.key.name &&
reg.test(node.parent.key.name.toLocaleLowerCase())
)
)
reg.test(node.parent.key.name.toLocaleLowerCase())))
) {
context.report({
node,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,7 @@ module.exports = {
const supports = target.__compat.support;
for (let i = 0, l = Object.keys(targetBrowsers).length; i < l; i++) {
const browser = Object.keys(targetBrowsers)[i];
if (
semver.satisfies(
`${targetBrowsers[browser]}.0.0`,
`<${supports[browser].version_added}`,
)
) {
if (semver.satisfies(`${targetBrowsers[browser]}.0.0`, `<${supports[browser].version_added}`)) {
context.report({
node,
messageId: 'recommendPolyfill',
Expand Down
4 changes: 4 additions & 0 deletions packages/spec/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# changelog

## 1.4.0

- ESLint add prettier config and plugin

## 1.3.2

- Add [eslint-plugin-jsx-plus](https://github.com/jsx-plus/eslint-plugin-jsx-plus) support Rax JSX+.
Expand Down
14 changes: 13 additions & 1 deletion packages/spec/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,22 @@ After that, you can add to your` package.json` the following code:

### Update from @ice/spec

If you are using [@ice/spce](https://www.npmjs.com/package/@ice/spec) in your project, we recommend use `@iceworks/spec` to get better maintainability and faster response to lint rules support.
If you are using [@ice/spec](https://www.npmjs.com/package/@ice/spec) in your project, we recommend use `@iceworks/spec` to get better maintainability and faster response to lint rules support.

Based on `@iceworks/spec`'s simple API you can quickly migrate your project, install and update your lint config file, the mission is completed 😁.

### Usage with Node.js API

If you are using spec rules in `CLIEngine` or `Linter`, Please set `cwd` to path of spec that can help ESLint find dependent plugins and configs.

```js
// CLIEngine
new CLIEngine({ cwd: path.dirname(require.resolve('@iceworks/spec')) });

// Linter
new Linter({ cwd: path.dirname(require.resolve('@iceworks/spec')) });
```

### 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`.
Expand Down
5 changes: 5 additions & 0 deletions packages/spec/examples/common-ts/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// prettier test
// const a = 1; const b = 2;
const a = 1;
const b = 2;

interface AppDeveloper {
name: string;
id: number;
Expand Down
5 changes: 5 additions & 0 deletions packages/spec/examples/common/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
// prettier test
// const a = 1; const b = 2;
const a = 1;
const b = 2;

const foo = [1, 2];
console.log(foo);
5 changes: 5 additions & 0 deletions packages/spec/examples/rax-ts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ interface LogoProps {

const unusedVar = 1;

// prettier test
// const a = 1; const b = 2;
const a = 1;
const b = 2;

export default (props: LogoProps) => {
const { uri } = props;
const source = { uri };
Expand Down
5 changes: 5 additions & 0 deletions packages/spec/examples/rax/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import './index.css';
const unusedVar = 1;

export default (props) => {
// prettier test
// const a = 1; const b = 2;
const a = 1;
const b = 2;

const { uri } = props;
const source = { uri };
return <Image className="logo" source={source} />;
Expand Down
13 changes: 6 additions & 7 deletions packages/spec/examples/react-ts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@ import styles from './index.module.scss';

const unusedVar = 1;

// prettier test
// const a = 1; const b = 2;
const a = 1;
const b = 2;

const TableActionIcon = Icon.createFromIconfontCN({
scriptUrl: '//at.alicdn.com/t/font_1899388_oxn3zhg34oj.js',
});

const getTableData = ({
current,
pageSize,
}: {
current: number;
pageSize: number;
}): Promise<any> => {
const getTableData = ({ current, pageSize }: { current: number; pageSize: number }): Promise<any> => {
const query = `page=${current}&size=${pageSize}`;
return fetch(`https://randomuser.me/api?results=${pageSize}&${query}`)
.then((res) => res.json())
Expand Down
9 changes: 6 additions & 3 deletions packages/spec/examples/react/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import styles from './index.module.scss';

const unusedVar = 1;

// prettier test
// const a = 1; const b = 2;
const a = 1;
const b = 2;

const PageHeader = (props) => {
const { breadcrumbs, title, description, ...others } = props;
return (
Expand All @@ -18,9 +23,7 @@ const PageHeader = (props) => {

{title && <Typography.Text className={styles.Title}>{title}</Typography.Text>}

{description && (
<Typography.Text className={styles.Description}>{description}</Typography.Text>
)}
{description && <Typography.Text className={styles.Description}>{description}</Typography.Text>}
</Box>
);
};
Expand Down
4 changes: 3 additions & 1 deletion packages/spec/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@iceworks/spec",
"version": "1.3.2",
"version": "1.4.0",
"description": "Easy to use eslint/stylelint/prettier/commitlint in rax, ice and react project.",
"main": "src/index.js",
"files": [
Expand Down Expand Up @@ -42,7 +42,9 @@
"babel-eslint": "^10.1.0",
"commitlint-config-ali": "^0.1.0",
"eslint-config-ali": "^12.0.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-jsx-plus": "^0.1.0",
"eslint-plugin-react": "^7.21.5",
"eslint-plugin-react-hooks": "^4.2.0",
Expand Down
2 changes: 2 additions & 0 deletions packages/spec/src/eslint/common-ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// ESlint config for common ts project
module.exports = {
extends: [
'plugin:prettier/recommended',
require.resolve('eslint-config-prettier'),
require.resolve('eslint-config-ali/typescript'),
],
rules: {
Expand Down
3 changes: 3 additions & 0 deletions packages/spec/src/eslint/common.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// https://www.npmjs.com/package/eslint-config-ali
// ESlint config for common js project

module.exports = {
extends: [
'plugin:prettier/recommended',
require.resolve('eslint-config-prettier'),
require.resolve('eslint-config-ali'),
],
rules: {
Expand Down
2 changes: 2 additions & 0 deletions packages/spec/src/eslint/rax-ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// ESlint config for Rax TypeScript project
module.exports = {
extends: [
'plugin:prettier/recommended',
require.resolve('eslint-config-prettier'),
require.resolve('eslint-config-ali/typescript/rax'),
// For some ci and jest test env, we chose require.resolve instead 'plugin:@iceworks/best-practices/rax-ts'
require.resolve('@iceworks/eslint-plugin-best-practices/src/configs/rax-ts'),
Expand Down
2 changes: 2 additions & 0 deletions packages/spec/src/eslint/rax.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// ESlint config for Rax project
module.exports = {
extends: [
'plugin:prettier/recommended',
require.resolve('eslint-config-prettier'),
require.resolve('eslint-config-ali/rax'),
// For some ci and jest test env, we chose require.resolve instead 'plugin:@iceworks/best-practices/rax'
require.resolve('@iceworks/eslint-plugin-best-practices/src/configs/rax'),
Expand Down
2 changes: 2 additions & 0 deletions packages/spec/src/eslint/react-ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// ESlint config for ice TypeScript and react TypeScript project
module.exports = {
extends: [
'plugin:prettier/recommended',
require.resolve('eslint-config-prettier'),
require.resolve('eslint-config-ali/typescript/react'),
// For some ci and jest test env, we chose require.resolve instead 'plugin:@iceworks/best-practices/react-ts'
require.resolve('@iceworks/eslint-plugin-best-practices/src/configs/react-ts'),
Expand Down
2 changes: 2 additions & 0 deletions packages/spec/src/eslint/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// ESlint config for ice and react project
module.exports = {
extends: [
'plugin:prettier/recommended',
require.resolve('eslint-config-prettier'),
require.resolve('eslint-config-ali/react'),
// For some ci and jest test env, we chose require.resolve instead 'plugin:@iceworks/best-practices/react'
require.resolve('@iceworks/eslint-plugin-best-practices/src/configs/react'),
Expand Down
4 changes: 1 addition & 3 deletions packages/spec/src/eslint/vue-ts.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// https://www.npmjs.com/package/eslint-config-ali
// ESlint config for Vue TypeScript project
module.exports = {
extends: [
require.resolve('eslint-config-ali/typescript/vue'),
],
extends: [require.resolve('eslint-config-ali/typescript/vue')],
rules: {
// Change error to warn
'@typescript-eslint/no-unused-vars': 'warn',
Expand Down
4 changes: 1 addition & 3 deletions packages/spec/src/eslint/vue.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// https://www.npmjs.com/package/eslint-config-ali
// ESlint config for Vue project
module.exports = {
extends: [
require.resolve('eslint-config-ali/vue'),
],
extends: [require.resolve('eslint-config-ali/vue')],
rules: {
// Change error to warn
'no-unused-vars': 'warn',
Expand Down