Skip to content

Commit 42fa163

Browse files
Damian SznajderDamian Sznajder
Damian Sznajder
authored and
Damian Sznajder
committed
chore: file restructure, add eslint & prettier
1 parent 5a23c71 commit 42fa163

File tree

11 files changed

+2195
-134
lines changed

11 files changed

+2195
-134
lines changed

.eslintrc.js

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
module.exports = {
2+
env: {
3+
es6: true,
4+
node: true,
5+
jest: true,
6+
},
7+
8+
plugins: ["simple-import-sort"],
9+
extends: ["satya164"],
10+
11+
rules: {
12+
"babel/no-unused-expressions": "off",
13+
"import/extensions": "off",
14+
"import/named": "off",
15+
"import/no-unresolved": "off",
16+
"jest/consistent-test-it": ["error", { fn: "test" }],
17+
"jest/no-truthy-falsy": "off",
18+
"jest/expect-expect": ["error", { assertFunctionNames: ["expect", "element"] }],
19+
20+
"prettier/prettier": [
21+
"error",
22+
{
23+
bracketSameLine: false,
24+
bracketSpacing: true,
25+
printWidth: 100,
26+
semi: true,
27+
singleQuote: false,
28+
tabWidth: 2,
29+
trailingComma: "all",
30+
useTabs: false,
31+
},
32+
],
33+
34+
"simple-import-sort/exports": "error",
35+
"simple-import-sort/imports": [
36+
"error",
37+
{
38+
groups: [
39+
// Side effect imports.
40+
["^\\u0000"],
41+
// Packages.
42+
["^@?\\w"],
43+
["^../"],
44+
["^./"],
45+
],
46+
},
47+
],
48+
49+
"@typescript-eslint/array-type": ["error", { default: "generic", readonly: "generic" }],
50+
},
51+
globals: {
52+
__DEV__: true,
53+
jasmine: true,
54+
},
55+
};

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ node_modules
44
*.vsix
55
*.log
66
.DS_Store
7+
lib/

.vscode/settings.json

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
{
2-
"files.exclude": {
3-
"out": false
2+
"editor.tabSize": 2,
3+
"javascript.format.enable": false,
4+
"typescript.format.enable": false,
5+
"typescript.tsdk": "node_modules/typescript/lib",
6+
"editor.defaultFormatter": "esbenp.prettier-vscode",
7+
"editor.codeActionsOnSave": {
8+
"source.fixAll.eslint": true
49
},
5-
"search.exclude": {
6-
"out": true
7-
},
8-
"typescript.tsc.autoDetect": "off",
9-
"prettier.semi": false,
10-
"prettier.singleQuote": true
1110
}

.vscodeignore

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
.vscode/**
2-
.vscode-test/**
3-
out/test/**
4-
extension/**
2+
src/**
53
.gitignore
6-
vsc-extension-quickstart.md
74
**/tsconfig.json
8-
**/tslint.json
9-
**/*.ts
5+
*.ts

extension/index.ts

-64
This file was deleted.

package.json

+40-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "es7-react-js-snippets",
3-
"displayName": "ES7 React/Redux/GraphQL/React-Native snippets",
4-
"description": "Simple extensions for React, Redux and Graphql in JS/TS with ES7 syntax",
3+
"displayName": "ES7+ React/Redux/GraphQL/React-Native snippets",
4+
"description": "Simple extensions for React, Redux and Graphql in JS/TS with ES7+ syntax",
55
"version": "3.2.0",
66
"publisher": "dsznajder",
77
"icon": "images/logo.png",
@@ -29,6 +29,13 @@
2929
"workspace"
3030
],
3131
"browser": "./out/extension.js",
32+
"main": "./lib/index.js",
33+
"capabilities": {
34+
"virtualWorkspaces": true,
35+
"untrustedWorkspaces": {
36+
"supported": true
37+
}
38+
},
3239
"activationEvents": [
3340
"onCommand:extension.snippetSearch"
3441
],
@@ -50,43 +57,62 @@
5057
"snippets": [
5158
{
5259
"language": "javascript",
53-
"path": "./snippets/snippets.json"
60+
"path": "./lib/snippets/snippets.json"
5461
},
5562
{
5663
"language": "javascriptreact",
57-
"path": "./snippets/snippets.json"
64+
"path": "./lib/snippets/snippets.json"
5865
},
5966
{
6067
"language": "typescript",
61-
"path": "./snippets/snippets.json"
68+
"path": "./lib/snippets/snippets.json"
6269
},
6370
{
6471
"language": "typescriptreact",
65-
"path": "./snippets/snippets.json"
72+
"path": "./lib/snippets/snippets.json"
6673
},
6774
{
6875
"language": "typescript",
69-
"path": "./snippets/ts-snippets.json"
76+
"path": "./lib/snippets/ts-snippets.json"
7077
},
7178
{
7279
"language": "typescriptreact",
73-
"path": "./snippets/ts-snippets.json"
80+
"path": "./lib/snippets/ts-snippets.json"
7481
}
7582
]
7683
},
7784
"scripts": {
7885
"vscode:prepublish": "yarn run package",
79-
"compile": "webpack",
80-
"watch": "webpack --watch",
81-
"package": "webpack --mode production --devtool hidden-source-map",
86+
"compile": "tsc -p ./ --noEmit false --outDir lib/",
87+
"compile:web": "webpack --mode production --devtool hidden-source-map",
88+
"watch": "tsc -watch -p ./",
89+
"watch:web": "webpack --watch",
90+
"package": "yarn compile && webpack --mode production --devtool hidden-source-map",
8291
"typescript": "tsc --noEmit"
8392
},
93+
"dependencies": {
94+
"vscode": "1.1.37"
95+
},
8496
"devDependencies": {
85-
"@types/node": "16.4.7",
86-
"@types/vscode": "1.58.1",
97+
"@types/node": "16.9.6",
98+
"@types/vscode": "1.60.0",
99+
"eslint": "7.32.0",
100+
"eslint-config-satya164": "3.1.10",
101+
"eslint-plugin-simple-import-sort": "7.0.0",
102+
"prettier": "2.4.1",
87103
"ts-loader": "^9.2.6",
88-
"typescript": "4.3.5",
104+
"typescript": "4.4.3",
89105
"webpack": "^5.64.4",
90106
"webpack-cli": "^4.9.1"
107+
},
108+
"prettier": {
109+
"bracketSameLine": false,
110+
"bracketSpacing": true,
111+
"printWidth": 100,
112+
"semi": true,
113+
"singleQuote": false,
114+
"tabWidth": 2,
115+
"trailingComma": "all",
116+
"useTabs": false
91117
}
92118
}

src/index.ts

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import * as vscode from "vscode";
2+
3+
import jsSnippets from "./snippets/snippets.json";
4+
import tsSnippets from "./snippets/ts-snippets.json";
5+
6+
const convertSnippetArrayToString = (snippetArray: Array<string>) => snippetArray.join("\n");
7+
8+
export function activate(context: vscode.ExtensionContext) {
9+
const {
10+
commands: { registerCommand },
11+
window: { showQuickPick, activeTextEditor },
12+
} = vscode;
13+
14+
const disposable = registerCommand("extension.snippetSearch", async () => {
15+
const javascriptSnippets = Object.entries(jsSnippets);
16+
const typescriptSnippets = Object.entries(tsSnippets);
17+
const snippetsArray = javascriptSnippets.concat(typescriptSnippets);
18+
19+
const items = snippetsArray.map(
20+
// @ts-expect-error
21+
([shortDescription, { prefix, body, description }], index) => {
22+
const value = typeof prefix === "string" ? prefix : prefix[0];
23+
24+
return {
25+
id: index,
26+
description: description || shortDescription,
27+
label: value,
28+
value,
29+
body,
30+
};
31+
},
32+
);
33+
34+
const options = {
35+
matchOnDescription: true,
36+
matchOnDetail: true,
37+
placeHolder: "Search snippet",
38+
};
39+
40+
const snippet = (await showQuickPick(items, options)) || {
41+
body: "",
42+
};
43+
44+
const body =
45+
typeof snippet.body === "string" ? snippet.body : convertSnippetArrayToString(snippet.body);
46+
47+
if (activeTextEditor) {
48+
activeTextEditor.insertSnippet(new vscode.SnippetString(body));
49+
}
50+
});
51+
52+
context.subscriptions.push(disposable);
53+
}
54+
55+
export function deactivate() {}
File renamed without changes.
File renamed without changes.

tsconfig.json

+17-11
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
{
22
"compilerOptions": {
3-
"lib": ["es2017"],
4-
"module": "commonjs",
5-
"outDir": "out",
6-
"rootDir": "extension",
3+
"allowJs": true,
4+
"allowSyntheticDefaultImports": true,
5+
"baseUrl": "./",
6+
"esModuleInterop": true,
7+
"module": "ESNext",
8+
"moduleResolution": "Node",
9+
"noEmit": true,
10+
"noImplicitAny": true,
11+
"noUnusedLocals": true,
12+
"noUnusedParameters": true,
13+
"resolveJsonModule": true,
14+
"skipDefaultLibCheck": true,
15+
"skipLibCheck": true,
716
"sourceMap": true,
817
"strict": true,
9-
"target": "es6",
10-
11-
/* Additional Checks */
12-
"noImplicitReturns": true,
13-
"noFallthroughCasesInSwitch": true,
14-
"noUnusedParameters": true
18+
"strictNullChecks": true,
19+
"target": "ESNext"
1520
},
16-
"exclude": ["node_modules", ".vscode-test"]
21+
"exclude": ["node_modules", "jest", "**/__tests__/*"],
22+
"compileOnSave": false
1723
}

0 commit comments

Comments
 (0)