Skip to content

Commit

Permalink
add lint
Browse files Browse the repository at this point in the history
  • Loading branch information
woohm402 committed Jun 13, 2024
1 parent 6df1ede commit 355b827
Show file tree
Hide file tree
Showing 11 changed files with 452 additions and 401 deletions.
30 changes: 0 additions & 30 deletions .eslintrc.json

This file was deleted.

1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ jobs:
with:
node-version: 18.x
- run: yarn
- run: yarn lint
- run: xvfb-run -a yarn test
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"singleQuote": true,
"semi": true,
"printWidth": 120,
"tabWidth": 2,
"trailingComma": "all"
}
4 changes: 2 additions & 2 deletions .vscode-test.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineConfig } from "@vscode/test-cli";
import { defineConfig } from '@vscode/test-cli';

export default defineConfig({
files: "out/test/**/*.test.js",
files: 'out/test/**/*.test.js',
});
28 changes: 13 additions & 15 deletions esbuild.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,40 @@
const esbuild = require("esbuild");
const esbuild = require('esbuild');

const production = process.argv.includes("--production");
const watch = process.argv.includes("--watch");
const production = process.argv.includes('--production');
const watch = process.argv.includes('--watch');

/**
* @type {import('esbuild').Plugin}
*/
const esbuildProblemMatcherPlugin = {
name: "esbuild-problem-matcher",
name: 'esbuild-problem-matcher',

setup(build) {
build.onStart(() => {
console.log("[watch] build started");
console.log('[watch] build started');
});
build.onEnd((result) => {
result.errors.forEach(({ text, location }) => {
console.error(`✘ [ERROR] ${text}`);
console.error(
` ${location.file}:${location.line}:${location.column}:`
);
console.error(` ${location.file}:${location.line}:${location.column}:`);
});
console.log("[watch] build finished");
console.log('[watch] build finished');
});
},
};

async function main() {
const ctx = await esbuild.context({
entryPoints: ["src/extension.ts"],
entryPoints: ['src/extension.ts'],
bundle: true,
format: "cjs",
format: 'cjs',
minify: production,
sourcemap: !production,
sourcesContent: false,
platform: "node",
outfile: "dist/extension.js",
external: ["vscode"],
logLevel: "silent",
platform: 'node',
outfile: 'dist/extension.js',
external: ['vscode'],
logLevel: 'silent',
plugins: [
/* add to the end of plugins array */
esbuildProblemMatcherPlugin,
Expand Down
8 changes: 8 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import config from '@woohm402/eslint-config-base';

export default [
{
ignores: ['esbuild.js', 'out', 'dist'],
},
...config,
];
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,21 @@
"watch-tests": "tsc -p . -w --outDir out",
"pretest": "yarn run compile-tests && yarn run compile && yarn run lint",
"check-types": "tsc --noEmit",
"lint": "eslint src --ext ts",
"lint": "eslint .",
"test": "vscode-test"
},
"devDependencies": {
"@types/mocha": "^10.0.6",
"@types/mocha": "10.0.6",
"@types/node": "18.x",
"@types/vscode": "^1.90.0",
"@typescript-eslint/eslint-plugin": "^7.11.0",
"@typescript-eslint/parser": "^7.11.0",
"@vscode/test-cli": "^0.0.9",
"@vscode/test-electron": "^2.4.0",
"@vscode/vsce": "^2.27.0",
"esbuild": "^0.21.4",
"eslint": "^8.57.0",
"npm-run-all": "^4.1.5",
"typescript": "^5.4.5"
"@types/vscode": "1.90.0",
"@vscode/test-cli": "0.0.9",
"@vscode/test-electron": "2.4.0",
"@vscode/vsce": "2.27.0",
"@woohm402/eslint-config-base": "0.1.0",
"esbuild": "0.21.4",
"eslint": "9.4.0",
"npm-run-all": "4.1.5",
"prettier": "3.3.2",
"typescript": "5.4.5"
}
}
66 changes: 28 additions & 38 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,37 @@
import * as vscode from "vscode";
import * as fs from 'fs';
import * as path from 'path';
import * as vscode from 'vscode';

import * as fs from "fs";
import * as path from "path";

import { componentTemplate, cssTemplate } from "./templates";
import { componentTemplate, cssTemplate } from './templates';

export function activate(context: vscode.ExtensionContext) {
let disposable = vscode.commands.registerCommand(
"createComponent",
async (uri) => {
const fp = uri.fsPath;
const componentName = await vscode.window.showInputBox({
placeHolder: "Enter Component Name",
validateInput: (value: string) => {
if (!value) {
return "Component Name Can't be Empty!";
}
return undefined;
},
});

if (componentName) {
const componentPath = path.join(fp, componentName);

if (!fs.existsSync(componentPath)) {
fs.mkdirSync(componentPath);

fs.writeFileSync(
path.join(componentPath, "index.tsx"),
componentTemplate(componentName)
);
fs.writeFileSync(
path.join(componentPath, "index.module.css"),
cssTemplate()
);

vscode.window.showInformationMessage(`Component Created!`);
} else {
vscode.window.showInformationMessage(`Component already Exist`);
const disposable = vscode.commands.registerCommand('createComponent', async (uri) => {
const fp = uri.fsPath;
const componentName = await vscode.window.showInputBox({
placeHolder: 'Enter Component Name',
validateInput: (value: string) => {
if (!value) {
return "Component Name Can't be Empty!";
}
return undefined;
},
});

if (componentName) {
const componentPath = path.join(fp, componentName);

if (!fs.existsSync(componentPath)) {
fs.mkdirSync(componentPath);

fs.writeFileSync(path.join(componentPath, 'index.tsx'), componentTemplate(componentName));
fs.writeFileSync(path.join(componentPath, 'index.module.css'), cssTemplate());

vscode.window.showInformationMessage(`Component Created!`);
} else {
vscode.window.showInformationMessage(`Component already Exist`);
}
}
);
});

context.subscriptions.push(disposable);
}
Expand Down
4 changes: 1 addition & 3 deletions src/templates/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ export const cssTemplate = () => `.wrapper {
}
`;

export const componentTemplate = (
componentName: string
) => `import styles from './index.module.css';
export const componentTemplate = (componentName: string) => `import styles from './index.module.css';
export const ${componentName} = ({
Expand Down
11 changes: 5 additions & 6 deletions src/test/extension.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import * as assert from 'assert';

// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
import * as vscode from 'vscode';
// import * as myExtension from '../../extension';

suite('Extension Test Suite', () => {
vscode.window.showInformationMessage('Start all tests.');
vscode.window.showInformationMessage('Start all tests.');

test('Sample test', () => {
assert.strictEqual(-1, [1, 2, 3].indexOf(5));
assert.strictEqual(-1, [1, 2, 3].indexOf(0));
});
test('Sample test', () => {
assert.strictEqual(-1, [1, 2, 3].indexOf(5));
assert.strictEqual(-1, [1, 2, 3].indexOf(0));
});
});
Loading

0 comments on commit 355b827

Please sign in to comment.