Skip to content

Commit e0cf3b5

Browse files
authored
Setup lint and prettier (#66)
* Fix lint * Setup lint and prettier
1 parent a0becf4 commit e0cf3b5

File tree

10 files changed

+422
-38
lines changed

10 files changed

+422
-38
lines changed

.husky/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npx lint-staged

.prettierrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"semi": true,
33
"tabWidth": 2,
4-
"printWidth": 100,
4+
"printWidth": 80,
55
"singleQuote": true,
66
"trailingComma": "none",
77
"jsxBracketSameLine": true

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ deploy:
1818
github_token: $github_token
1919
local_dir: example/build
2020
on:
21-
branch: master
21+
branch: main

README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ yarn add react-copy-button
1616

1717
```jsx
1818
// Functional Component with useRef hook.
19-
import React from "react";
20-
import { useRef } from "react";
21-
import { useState } from "react";
19+
import React from 'react';
20+
import { useRef } from 'react';
21+
import { useState } from 'react';
2222

2323
function App() {
2424
const imgRef = useRef();
@@ -35,9 +35,9 @@ function App() {
3535
}
3636

3737
// Class Component
38-
import * as React from "react";
38+
import * as React from 'react';
3939

40-
import CopyButton from "react-copy-button";
40+
import CopyButton from 'react-copy-button';
4141

4242
class Example extends React.Component {
4343
constructor(props) {
@@ -60,6 +60,12 @@ class Example extends React.Component {
6060
}
6161
```
6262

63+
## Development
64+
65+
```bash
66+
pnpm install
67+
```
68+
6369
## Browser compatibility
6470

6571
For browser compatibility check [here](https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand#Browser_compatibility).

example/src/App.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import React from "react";
2-
import { useRef } from "react";
3-
import { useState } from "react";
1+
import React from 'react';
2+
import { useRef } from 'react';
3+
import { useState } from 'react';
44

5-
import { CopyButton } from "react-copy-button";
5+
import { CopyButton } from 'react-copy-button';
66

77
const TIMEOUT_DURATION = 1000;
88

99
function App() {
1010
const imgRef = useRef();
1111
const [isTextCopied, setTextCopied] = useState(false);
1212
const [isImageCopied, setImageCopied] = useState(false);
13-
const [copyValue, updateValues] = useState({ copy: "", image: "" });
13+
const [copyValue, updateValues] = useState({ copy: '', image: '' });
1414

1515
const handleChange = (event) =>
1616
updateValues({ ...copyValue, [event.target.name]: event.target.value });
@@ -46,7 +46,7 @@ function App() {
4646
text={copyValue.text}
4747
onClick={handleTextCopy}
4848
>
49-
{isTextCopied ? "Text Copied!" : "Copy Text"}
49+
{isTextCopied ? 'Text Copied!' : 'Copy Text'}
5050
</CopyButton>
5151
<hr />
5252
<input
@@ -56,12 +56,12 @@ function App() {
5656
placeholder="Paste image url here"
5757
onChange={handleChange}
5858
/>
59-
<div style={{ textAlign: "center", padding: 40 }} ref={imgRef}>
59+
<div style={{ textAlign: 'center', padding: 40 }} ref={imgRef}>
6060
<img
6161
height={400}
6262
src={
6363
copyValue.image ||
64-
"https://upload.wikimedia.org/wikipedia/commons/thumb/a/a7/React-icon.svg/2000px-React-icon.svg.png"
64+
'https://upload.wikimedia.org/wikipedia/commons/thumb/a/a7/React-icon.svg/2000px-React-icon.svg.png'
6565
}
6666
alt="React Copy Button"
6767
/>
@@ -71,7 +71,7 @@ function App() {
7171
imgRef={imgRef}
7272
onClick={handleImageCopy}
7373
>
74-
{isImageCopied ? "Image Copied!" : "Copy Image"}
74+
{isImageCopied ? 'Image Copied!' : 'Copy Image'}
7575
</CopyButton>
7676
</div>
7777
</div>

package.json

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-copy-button",
3-
"version": "0.0.4",
3+
"version": "0.1.0",
44
"homepage": "https://cham11ng.github.io/react-copy-button",
55
"description": "Copy to clipboard react button component.",
66
"author": "cham11ng",
@@ -16,13 +16,20 @@
1616
"scripts": {
1717
"build": "rollup -c",
1818
"start": "rollup -c -w",
19-
"prepare": "yarn run build",
19+
"prepare": "yarn run build && husky install",
2020
"predeploy": "cd example && yarn install && yarn run build",
2121
"deploy": "gh-pages -d example/build",
2222
"lint": "eslint .",
23-
"lint:fix": "eslint --fix . --ext .ts,.tsx",
23+
"lint:fix": "eslint --fix .",
2424
"prettify": "prettier --write './**/*.{js,jsx,ts,tsx,css,md,json}'"
2525
},
26+
"lint-staged": {
27+
"*.{js,ts,jsx,tsx}": "eslint --fix",
28+
"*.{js,ts,jsx,tsx,css,md,json}": "prettier --write"
29+
},
30+
"files": [
31+
"dist"
32+
],
2633
"devDependencies": {
2734
"@rollup/plugin-commonjs": "^22.0.1",
2835
"@rollup/plugin-node-resolve": "^13.3.0",
@@ -36,14 +43,13 @@
3643
"eslint-plugin-prettier": "^4.2.1",
3744
"eslint-plugin-react": "^7.30.1",
3845
"gh-pages": "^4.0.0",
46+
"husky": "^8.0.1",
47+
"lint-staged": "^13.0.3",
3948
"prettier": "^2.7.1",
4049
"react": "^18.2.0",
4150
"react-dom": "^18.2.0",
4251
"rollup": "^2.75.7",
4352
"tslib": "^2.4.0",
4453
"typescript": "^4.7.4"
45-
},
46-
"files": [
47-
"dist"
48-
]
54+
}
4955
}

0 commit comments

Comments
 (0)