Skip to content

Commit 83d3b31

Browse files
authored
enforce eslint (#312)
* reformat * add eslint
1 parent 4ed23b5 commit 83d3b31

File tree

9 files changed

+5645
-97
lines changed

9 files changed

+5645
-97
lines changed

.eslintrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
extends: ['@react-native-community'],
3+
};

.github/workflows/nodejs.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3+
4+
name: Node.js CI
5+
6+
on:
7+
push:
8+
branches: [master]
9+
pull_request:
10+
branches: [master]
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
16+
strategy:
17+
matrix:
18+
node-version: [12.x]
19+
20+
steps:
21+
- uses: actions/checkout@v2
22+
- name: Use Node.js ${{ matrix.node-version }}
23+
uses: actions/setup-node@v1
24+
with:
25+
node-version: ${{ matrix.node-version }}
26+
- run: yarn install --frozen-lockfile
27+
- run: yarn lint
28+
env:
29+
CI: true

.prettierrc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
printWidth: 100,
3+
singleQuote: true,
4+
trailingComma: 'es5',
5+
};

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,4 +250,3 @@ RNFS.uploadFiles({
250250

251251
- Fix Xcode warning about constraints
252252
- support options for the [UIDocumentPickerViewController](https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/DocumentPickerProgrammingGuide/AccessingDocuments/AccessingDocuments.html#//apple_ref/doc/uid/TP40014451-CH2-SW5)
253-
- Handle Upload by itself ?

__tests__/typescript/index.test.ts

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,78 @@
1-
import DocumentPicker from "react-native-document-picker";
1+
import DocumentPicker from 'react-native-document-picker';
22

33
// Option is correct about pick
44
DocumentPicker.pick({
5-
type: [DocumentPicker.types.allFiles]
6-
})
5+
type: [DocumentPicker.types.allFiles],
6+
});
77

88
DocumentPicker.pick({
9-
type: [DocumentPicker.types.audio]
10-
})
9+
type: [DocumentPicker.types.audio],
10+
});
1111

1212
DocumentPicker.pick({
13-
type: [DocumentPicker.types.images]
14-
})
13+
type: [DocumentPicker.types.images],
14+
});
1515

1616
DocumentPicker.pick({
17-
type: [DocumentPicker.types.plainText]
18-
})
17+
type: [DocumentPicker.types.plainText],
18+
});
1919

2020
DocumentPicker.pick({
21-
type: [DocumentPicker.types.video]
22-
})
21+
type: [DocumentPicker.types.video],
22+
});
2323

2424
DocumentPicker.pick({
25-
type: [DocumentPicker.types.pdf]
26-
})
25+
type: [DocumentPicker.types.pdf],
26+
});
2727

2828
DocumentPicker.pick({
29-
type: [DocumentPicker.types.video,DocumentPicker.types.pdf, 'public.audio']
30-
})
29+
type: [DocumentPicker.types.video, DocumentPicker.types.pdf, 'public.audio'],
30+
});
3131

3232
// Option is correct about pickMultiple
3333

3434
DocumentPicker.pickMultiple({
35-
type: [DocumentPicker.types.allFiles]
36-
})
35+
type: [DocumentPicker.types.allFiles],
36+
});
3737

3838
DocumentPicker.pickMultiple({
39-
type: [DocumentPicker.types.allFiles]
40-
})
39+
type: [DocumentPicker.types.allFiles],
40+
});
4141

4242
DocumentPicker.pickMultiple({
43-
type: [DocumentPicker.types.audio]
44-
})
43+
type: [DocumentPicker.types.audio],
44+
});
4545

4646
DocumentPicker.pickMultiple({
47-
type: [DocumentPicker.types.images]
48-
})
47+
type: [DocumentPicker.types.images],
48+
});
4949

5050
DocumentPicker.pickMultiple({
51-
type: [DocumentPicker.types.plainText]
52-
})
51+
type: [DocumentPicker.types.plainText],
52+
});
5353

5454
DocumentPicker.pickMultiple({
55-
type: [DocumentPicker.types.video]
56-
})
55+
type: [DocumentPicker.types.video],
56+
});
5757

5858
DocumentPicker.pickMultiple({
59-
type: [DocumentPicker.types.pdf]
60-
})
59+
type: [DocumentPicker.types.pdf],
60+
});
6161

6262
DocumentPicker.pickMultiple({
63-
type: [DocumentPicker.types.video,DocumentPicker.types.pdf, 'public.audio']
64-
})
63+
type: [DocumentPicker.types.video, DocumentPicker.types.pdf, 'public.audio'],
64+
});
6565

66-
DocumentPicker.pick({type: 'image/jpg'});
67-
DocumentPicker.pick({type: 'public.png'});
68-
69-
DocumentPicker.pick({type: ['image/jpg', 'image/jpeg', 'image/png', 'application/pdf']});
70-
DocumentPicker.pick({type: ['public.png', 'public.jpeg']});
66+
DocumentPicker.pick({ type: 'image/jpg' });
67+
DocumentPicker.pick({ type: 'public.png' });
7168

69+
DocumentPicker.pick({ type: ['image/jpg', 'image/jpeg', 'image/png', 'application/pdf'] });
70+
DocumentPicker.pick({ type: ['public.png', 'public.jpeg'] });
7271

7372
try {
74-
throw new Error('test')
73+
throw new Error('test');
7574
} catch (e) {
76-
if(DocumentPicker.isCancel(e)){
77-
75+
if (DocumentPicker.isCancel(e)) {
7876
} else {
79-
8077
}
8178
}

index.d.ts

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,51 @@ declare module 'react-native-document-picker' {
44
type Extension = '.jpeg' | '.jpg' | '.png' | '.txt' | '.pdf';
55

66
type DocumentType = {
7-
android: MimeType | MimeType[]
8-
ios: UTI | UTI[]
9-
windows: Extension | Extension[]
7+
android: MimeType | MimeType[];
8+
ios: UTI | UTI[];
9+
windows: Extension | Extension[];
1010
};
1111

1212
type Types = {
1313
mimeTypes: {
14-
allFiles: '*/*',
15-
audio: 'audio/*',
16-
csv: 'text/csv',
17-
images: 'image/*',
18-
plainText: 'text/plain',
19-
pdf: 'application/pdf',
20-
video: 'video/*',
21-
zip: 'application/zip',
22-
},
14+
allFiles: '*/*';
15+
audio: 'audio/*';
16+
csv: 'text/csv';
17+
images: 'image/*';
18+
plainText: 'text/plain';
19+
pdf: 'application/pdf';
20+
video: 'video/*';
21+
zip: 'application/zip';
22+
};
2323
utis: {
24-
allFiles: 'public.content',
25-
audio: 'public.audio',
26-
csv: 'public.comma-separated-values-text',
27-
images: 'public.image',
28-
plainText: 'public.plain-text',
29-
pdf: 'com.adobe.pdf',
30-
video: 'public.movie',
31-
zip: 'public.zip-archive',
32-
},
24+
allFiles: 'public.content';
25+
audio: 'public.audio';
26+
csv: 'public.comma-separated-values-text';
27+
images: 'public.image';
28+
plainText: 'public.plain-text';
29+
pdf: 'com.adobe.pdf';
30+
video: 'public.movie';
31+
zip: 'public.zip-archive';
32+
};
3333
extensions: {
34-
allFiles: '*',
35-
audio:
36-
'.3g2 .3gp .aac .adt .adts .aif .aifc .aiff .asf .au .m3u .m4a .m4b .mid .midi .mp2 .mp3 .mp4 .rmi .snd .wav .wax .wma',
37-
csv: '.csv',
38-
images: '.jpeg .jpg .png',
39-
plainText: '.txt',
40-
pdf: '.pdf',
41-
video: '.mp4',
42-
zip: '.zip .gz',
43-
},
34+
allFiles: '*';
35+
audio: '.3g2 .3gp .aac .adt .adts .aif .aifc .aiff .asf .au .m3u .m4a .m4b .mid .midi .mp2 .mp3 .mp4 .rmi .snd .wav .wax .wma';
36+
csv: '.csv';
37+
images: '.jpeg .jpg .png';
38+
plainText: '.txt';
39+
pdf: '.pdf';
40+
video: '.mp4';
41+
zip: '.zip .gz';
42+
};
4443
};
4544
type PlatformTypes = {
46-
android: Types['mimeTypes']
47-
ios: Types['utis']
48-
windows: Types['extensions']
45+
android: Types['mimeTypes'];
46+
ios: Types['utis'];
47+
windows: Types['extensions'];
4948
};
5049
interface DocumentPickerOptions<OS extends keyof PlatformTypes> {
5150
type: Array<PlatformTypes[OS][keyof PlatformTypes[OS]]> | DocumentType[OS];
52-
copyTo?: 'cachesDirectory' | 'documentDirectory';
51+
copyTo?: 'cachesDirectory' | 'documentDirectory';
5352
}
5453
interface DocumentPickerResponse {
5554
uri: string;
@@ -59,15 +58,15 @@ declare module 'react-native-document-picker' {
5958
name: string;
6059
size: string;
6160
}
62-
type Platform = 'ios' | 'android' | 'windows'
61+
type Platform = 'ios' | 'android' | 'windows';
6362
export default class DocumentPicker<OS extends keyof PlatformTypes = Platform> {
64-
static types: PlatformTypes['ios'] | PlatformTypes['android'] | PlatformTypes['windows']
63+
static types: PlatformTypes['ios'] | PlatformTypes['android'] | PlatformTypes['windows'];
6564
static pick<OS extends keyof PlatformTypes = Platform>(
6665
options: DocumentPickerOptions<OS>
6766
): Promise<DocumentPickerResponse>;
6867
static pickMultiple<OS extends keyof PlatformTypes = Platform>(
6968
options: DocumentPickerOptions<OS>
7069
): Promise<DocumentPickerResponse[]>;
71-
static isCancel<IError extends {code?: string}>(err?: IError): boolean;
70+
static isCancel<IError extends { code?: string }>(err?: IError): boolean;
7271
}
7372
}

index.js

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function pick(opts) {
3838

3939
opts.type = Array.isArray(opts.type) ? opts.type : [opts.type];
4040

41-
if (opts.type.some(type => type === undefined)) {
41+
if (opts.type.some((type) => type === undefined)) {
4242
throw new TypeError(
4343
'Unexpected undefined type option, did you try using a DocumentPicker.types.* that does not exist?'
4444
);
@@ -50,23 +50,15 @@ function pick(opts) {
5050
);
5151
}
5252

53-
opts.type.forEach(type => {
53+
opts.type.forEach((type) => {
5454
if (typeof type !== 'string') {
55-
throw new TypeError(
56-
'Invalid type option, expected a string not: ' + type
57-
);
55+
throw new TypeError('Invalid type option, expected a string not: ' + type);
5856
}
5957
});
6058

61-
if (
62-
opts.type.length > 1 &&
63-
Platform.OS === 'android' &&
64-
Platform.Version < 19
65-
) {
59+
if (opts.type.length > 1 && Platform.OS === 'android' && Platform.Version < 19) {
6660
console.warn(
67-
`RNDocumentPicker: Android API level ${
68-
Platform.Version
69-
} does not support multiple types, falling back to */*`
61+
`RNDocumentPicker: Android API level ${Platform.Version} does not support multiple types, falling back to */*`
7062
);
7163
}
7264

@@ -86,7 +78,7 @@ const Types = {
8678
plainText: 'text/plain',
8779
pdf: 'application/pdf',
8880
video: 'video/*',
89-
zip: 'application/zip'
81+
zip: 'application/zip',
9082
},
9183
utis: {
9284
allFiles: 'public.content',
@@ -107,6 +99,7 @@ const Types = {
10799
plainText: '.txt',
108100
pdf: '.pdf',
109101
video: '.mp4',
102+
zip: '.zip .gz',
110103
},
111104
};
112105

@@ -130,7 +123,7 @@ export default class DocumentPicker {
130123
multiple: false,
131124
};
132125

133-
return pick(options).then(results => results[0]);
126+
return pick(options).then((results) => results[0]);
134127
}
135128

136129
static pickMultiple(opts) {

package.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"description": "A react native interface to access Documents from dropbox google drive, iCloud",
55
"main": "index.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"lint": "eslint ."
89
},
910
"repository": {
1011
"type": "git",
@@ -29,7 +30,13 @@
2930
"react-native": ">= 0.33"
3031
},
3132
"devDependencies": {
33+
"@react-native-community/eslint-config": "^2.0.0",
34+
"eslint": "^7.2.0",
35+
"eslint-plugin-prettier": "^3.1.3",
36+
"prettier": "^2.0.5",
3237
"react": "^16.0.0-beta.5",
33-
"react-native": "^0.49.3"
34-
}
38+
"react-native": "^0.49.3",
39+
"typescript": "^3.9.5"
40+
},
41+
"dependencies": {}
3542
}

0 commit comments

Comments
 (0)