diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 0000000..fa4746f --- /dev/null +++ b/.github/workflows/pr.yml @@ -0,0 +1,50 @@ +name: pr-check + +on: + pull_request: + types: + # default types + - opened + - reopened + - synchronize + # run when PR title or body changes + - edited + branches: + - main +jobs: + lint-and-format: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: "lts/iron" + cache: "npm" + + - name: Install dependencies + run: npm install + + - name: Check that project is able to be packaged + run: npm run package + + - name: Check that PR title follows conventional commits using regex + env: + TITLE: ${{ github.event.pull_request.title }} + run: | + echo "Your PR title is '$TITLE'" + + regex="(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\([a-z[[:space:]]+\))?:[[:space:]].+" + + if [[ $TITLE =~ $regex ]]; then + echo "PR title follows conventional commits" + else + echo "PR title does not follow conventional commits format" + echo "Prefix your PR title with a descriptor such as 'feat:' and then summarize your change" + echo "See the following link for more information: https://www.conventionalcommits.org/en/v1.0.0/" + exit 1 + fi diff --git a/.gitignore b/.gitignore index 747d976..d2703e4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ node_modules dist -.vsix +*.vsix diff --git a/.vscode/launch.json b/.vscode/launch.json index c42edc0..81b773f 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,7 +1,3 @@ -// A launch configuration that compiles the extension and then opens it inside a new window -// Use IntelliSense to learn about possible attributes. -// Hover to view descriptions of existing attributes. -// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 { "version": "0.2.0", "configurations": [ diff --git a/.vscode/tasks.json b/.vscode/tasks.json index a425a85..b4ae625 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,5 +1,3 @@ -// See https://go.microsoft.com/fwlink/?LinkId=733558 -// for the documentation about the tasks.json format { "version": "2.0.0", "tasks": [ diff --git a/.vscodeignore b/.vscodeignore index 826face..3862469 100644 --- a/.vscodeignore +++ b/.vscodeignore @@ -1,12 +1,13 @@ -.vscode/** -out/** +.github +.vscode node_modules/** +!node_modules/prettier src/** +**/*.map .gitignore -.yarnrc +.prettierrc esbuild.js -vsc-extension-quickstart.md -**/tsconfig.json -**/eslint.config.mjs -**/*.map -**/*.ts +eslint.config.mjs +package-lock.json +tsconfig.json +*.vsix \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 4139ba6..5bd1ed1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,10 @@ -# Change Log +# Changelog -All notable changes to the "prettier-plugin-java-vscode" extension will be documented in this file. +All notable changes to this project will be documented in this file. -Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased] +## [1.0.0] -- Initial release \ No newline at end of file +- Initial release diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..aef5298 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) [2025] [Rudra Patel] + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index 928fb4e..31d5e39 100644 --- a/README.md +++ b/README.md @@ -1,71 +1,29 @@ -# prettier-plugin-java-vscode README +# Prettier Java Plugin -This is the README for your extension "prettier-plugin-java-vscode". After writing up a brief description, we recommend including the following sections. +A VSCode extension to format Java files with Prettier using prettier-plugin-java. ## Features -Describe specific features of your extension including screenshots of your extension in action. Image paths are relative to this README file. - -For example if there is an image subfolder under your extension project workspace: - -\!\[feature X\]\(images/feature-x.png\) - -> Tip: Many popular extensions utilize animations. This is an excellent way to show off your extension! We recommend short, focused animations that are easy to follow. - -## Requirements - -If you have any requirements or dependencies, add a section describing those and how to install and configure them. +- Format Java files with no configuration necessary +- Specify a Prettier config file to use if desired ## Extension Settings -Include if your extension adds any VS Code settings through the `contributes.configuration` extension point. +To set this formatter as the default formatter for Java files, add the following to your VSCode settings: -For example: +```json +"[java]": { + "editor.defaultFormatter": "RudraPatel.prettier-plugin-java-vscode" + } +``` This extension contributes the following settings: -* `myExtension.enable`: Enable/disable this extension. -* `myExtension.thing`: Set to `blah` to do something. - -## Known Issues - -Calling out known issues can help limit users opening duplicate issues against your extension. +- `prettier-plugin-java-vscode.enabled`: Enable/disable the plugin. +- `prettier-plugin-java-vscode.prettierConfigPath`: Provide a absolution path to your prettier configuration file. ## Release Notes -Users appreciate release notes as you update your extension. - ### 1.0.0 -Initial release of ... - -### 1.0.1 - -Fixed issue #. - -### 1.1.0 - -Added features X, Y, and Z. - ---- - -## Following extension guidelines - -Ensure that you've read through the extensions guidelines and follow the best practices for creating your extension. - -* [Extension Guidelines](https://code.visualstudio.com/api/references/extension-guidelines) - -## Working with Markdown - -You can author your README using Visual Studio Code. Here are some useful editor keyboard shortcuts: - -* Split the editor (`Cmd+\` on macOS or `Ctrl+\` on Windows and Linux). -* Toggle preview (`Shift+Cmd+V` on macOS or `Shift+Ctrl+V` on Windows and Linux). -* Press `Ctrl+Space` (Windows, Linux, macOS) to see a list of Markdown snippets. - -## For more information - -* [Visual Studio Code's Markdown Support](http://code.visualstudio.com/docs/languages/markdown) -* [Markdown Syntax Reference](https://help.github.com/articles/markdown-basics/) - -**Enjoy!** +- Initial release diff --git a/icon.png b/icon.png new file mode 100644 index 0000000..71f2515 Binary files /dev/null and b/icon.png differ diff --git a/package.json b/package.json index fbfd126..1d7eb6f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "prettier-plugin-java-vscode", - "displayName": "prettier-plugin-java For VSCode", - "description": "A VSCode plugin that uses prettier-plugin-java to format .java files. Based on the now removed mwpb.java-prettier-formatter extension.", + "displayName": "Prettier Java Plugin", + "description": "Format Java files with Prettier using prettier-plugin-java.", "version": "1.0.0", "publisher": "RudraPatel", "license": "MIT", @@ -25,8 +25,9 @@ "categories": [ "Formatters" ], + "icon": "icon.png", "activationEvents": [ - "onLanguage:java" + "onStartupFinished" ], "main": "./dist/extension.js", "contributes": { @@ -43,7 +44,7 @@ } ], "configuration": { - "title": "Prettier Plugin Java VSCode", + "title": "Prettier Java Plugin", "properties": { "prettier-plugin-java-vscode.prettierConfigPath": { "type": ["string", "null"], diff --git a/src/extension.ts b/src/extension.ts index 3912c81..14c2144 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -21,7 +21,7 @@ async function formatJavaDocument( const isEnabled = checkIfEnabled(); if (!isEnabled) { - log("Prettier Plugin Java VSCode is disabled"); + log("Prettier Plugin Java VSCode is disabled\n"); return null; } @@ -50,13 +50,13 @@ async function formatJavaDocument( const elapsedTime = Date.now() - start; - log(`Formatted ${document.fileName} in ${elapsedTime}ms.`); + log(`Formatted ${document.fileName} in ${elapsedTime}ms\n`); return [TextEdit.replace(entireDocumentRange, formattedText)]; } export function activate(context: ExtensionContext) { - log("Prettier Plugin Java VSCode activated."); + log("Prettier Plugin Java VSCode activated\n"); const disposable = languages.registerDocumentFormattingEditProvider("java", { provideDocumentFormattingEdits: formatJavaDocument, diff --git a/src/logger.ts b/src/logger.ts index 1e7c7e5..4649b18 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -1,9 +1,7 @@ import { window } from "vscode"; // Create the output channel once at the module level -export const outputChannel = window.createOutputChannel( - "Prettier Plugin Java VSCode", -); +export const outputChannel = window.createOutputChannel("Prettier Java Plugin"); function getFormattedTime(): string { return new Date().toLocaleTimeString("en-US"); diff --git a/src/prettier-plugin-java.d.ts b/src/types/prettier-plugin-java.d.ts similarity index 100% rename from src/prettier-plugin-java.d.ts rename to src/types/prettier-plugin-java.d.ts diff --git a/src/utils.ts b/src/utils.ts index 36d5030..a52989f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -31,7 +31,7 @@ async function getPretterConfigPath(document: TextDocument): Promise { if (!fileExists) { log( - `Specified Prettier config file (${userProvidedConfigPath}) does not exist.`, + `Specified Prettier config file (${userProvidedConfigPath}) does not exist`, ); log( `Prettier will attempt to resolve the config file from the document file name (${document.fileName})`, @@ -45,7 +45,7 @@ async function getPretterConfigPath(document: TextDocument): Promise { return userProvidedConfigPath; } - log("No specified Prettier config file."); + log("No specified Prettier config file"); log( `Prettier will attempt to resolve the config file from the document file name (${document.fileName})`, ); diff --git a/vsc-extension-quickstart.md b/vsc-extension-quickstart.md deleted file mode 100644 index f518bb8..0000000 --- a/vsc-extension-quickstart.md +++ /dev/null @@ -1,48 +0,0 @@ -# Welcome to your VS Code Extension - -## What's in the folder - -* This folder contains all of the files necessary for your extension. -* `package.json` - this is the manifest file in which you declare your extension and command. - * The sample plugin registers a command and defines its title and command name. With this information VS Code can show the command in the command palette. It doesn’t yet need to load the plugin. -* `src/extension.ts` - this is the main file where you will provide the implementation of your command. - * The file exports one function, `activate`, which is called the very first time your extension is activated (in this case by executing the command). Inside the `activate` function we call `registerCommand`. - * We pass the function containing the implementation of the command as the second parameter to `registerCommand`. - -## Setup - -* install the recommended extensions (amodio.tsl-problem-matcher, ms-vscode.extension-test-runner, and dbaeumer.vscode-eslint) - - -## Get up and running straight away - -* Press `F5` to open a new window with your extension loaded. -* Run your command from the command palette by pressing (`Ctrl+Shift+P` or `Cmd+Shift+P` on Mac) and typing `Hello World`. -* Set breakpoints in your code inside `src/extension.ts` to debug your extension. -* Find output from your extension in the debug console. - -## Make changes - -* You can relaunch the extension from the debug toolbar after changing code in `src/extension.ts`. -* You can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with your extension to load your changes. - - -## Explore the API - -* You can open the full set of our API when you open the file `node_modules/@types/vscode/index.d.ts`. - -## Run tests - -* Install the [Extension Test Runner](https://marketplace.visualstudio.com/items?itemName=ms-vscode.extension-test-runner) -* Run the "watch" task via the **Tasks: Run Task** command. Make sure this is running, or tests might not be discovered. -* Open the Testing view from the activity bar and click the Run Test" button, or use the hotkey `Ctrl/Cmd + ; A` -* See the output of the test result in the Test Results view. -* Make changes to `src/test/extension.test.ts` or create new test files inside the `test` folder. - * The provided test runner will only consider files matching the name pattern `**.test.ts`. - * You can create folders inside the `test` folder to structure your tests any way you want. - -## Go further - -* Reduce the extension size and improve the startup time by [bundling your extension](https://code.visualstudio.com/api/working-with-extensions/bundling-extension). -* [Publish your extension](https://code.visualstudio.com/api/working-with-extensions/publishing-extension) on the VS Code extension marketplace. -* Automate builds by setting up [Continuous Integration](https://code.visualstudio.com/api/working-with-extensions/continuous-integration).