Skip to content

Commit

Permalink
添加新配置
Browse files Browse the repository at this point in the history
useignoreExtension: 是否使用 过滤规则扩展
  • Loading branch information
xiaohuohumax committed Mar 24, 2024
1 parent 75fa659 commit 4e14c70
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/swift-buses-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"format-files-by-ignores": minor
---

添加配置 useignoreExtension: 是否使用过滤规则扩展
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ VSCode Extensions Select `Format Files By Ignores`

## ⚙ Options

- `formatFilesByIgnores.useignoreExtension`: Is use ignore extension ?
- `default`: true
- `formatFilesByIgnores.ignoreExtension`: Ignore extension rules (root folder)
- `default`: [ "node_modules", ".vscode", ".git", "dist" ]
- `formatFilesByIgnores.ignoreFileNames`: Ignore files name
Expand Down
2 changes: 2 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ VSCode 插件搜索 `Format Files By Ignores`

## 配置

- `formatFilesByIgnores.useignoreExtension`: 是否使用 过滤规则扩展
- `default`: true
- `formatFilesByIgnores.ignoreExtension`: 文件夹根目录 `ignore` 过滤规则扩展
- `default`: [ "node_modules", ".vscode", ".git", "dist" ]
- `formatFilesByIgnores.ignoreFileNames`: `Ignore` 文件的名称
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
"configuration": [
{
"properties": {
"formatFilesByIgnores.useIgnoreExtension": {
"scope": "resource",
"type": "boolean",
"description": "Is use ignore extension ?",
"default": true
},
"formatFilesByIgnores.ignoreExtension": {
"scope": "resource",
"type": "array",
Expand Down
2 changes: 2 additions & 0 deletions src/commands/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as vscode from 'vscode';
import { Message } from '../util/message';
import { OperationAborted } from '../error';
import { Logger } from '../util/logger';
import { FormatConfig } from '../config';

/**
* 配置
Expand Down Expand Up @@ -49,6 +50,7 @@ export abstract class Command {

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const callback = async (...args: any[]) => {
Logger.info(JSON.stringify(FormatConfig.config));
Logger.debug(`Command '${this.options.key}' callback args: ${args}`);
try {
return await this.callback(...args);
Expand Down
8 changes: 7 additions & 1 deletion src/commands/formatFolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,17 @@ export class FormatFolder extends Command {
// 打开输出面板
Logger.show(true);

const extensions: string[] = [];

if (FormatConfig.config.useIgnoreExtension) {
extensions.push(...FormatConfig.config.ignoreExtension);
}

// 筛选全部需要格式化的文件
const files = filterFolderByignore(
folder.fsPath,
// 全局扩展
FormatConfig.config.ignoreExtension,
extensions,
// ignore 文件名称
FormatConfig.config.ignoreFileNames
);
Expand Down
9 changes: 6 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { workspace } from 'vscode';

export interface Config {

// todo 添加是否开启忽略扩展
/**
* 添加是否开启忽略扩展
*/
useIgnoreExtension: boolean
/**
* 忽略扩展(仅限根目录)
*/
ignoreExtension: []
ignoreExtension: string[]
/**
* ignore 文件名称
*
Expand All @@ -21,6 +23,7 @@ export interface Config {
export class FormatConfig {
public static get config(): Config {
return workspace.getConfiguration().get<Config>('formatFilesByIgnores', {
useIgnoreExtension: true,
ignoreExtension: [],
ignoreFileNames: []
});
Expand Down

0 comments on commit 4e14c70

Please sign in to comment.