Qodana 2024.1 ヘルプ

カスタム YAML プロファイル

バージョン 2023.2 以降では、YAML を使用して Qodana プロファイルを作成および構成できます。Qodana では、プロファイル構成に関連する次のようないくつかの改善も提供されています。

  • ファイルパスとスコープのサポート

  • インスペクションパラメーターのサポート

  • プロファイル関係。プロファイルを拡張して含めることができます

このサンプルでは、ニーズに合わせて Qodana を微調整する方法を示します。

name: "My custom profile" # Profile name baseProfile: empty # Use the 'empty' profile as initial configuration of this profile include: - ".qodana/profiles/other-profile.yaml" # The included file becomes part of this profile groups: # List of configured groups - groupId: InspectionsToInclude groups: - "category:PHP/General" # Inspection category from the linter - "JSCategories" # Include the JSCategories group from below - "PHPInspections" # Include the PHPInspections group from below - groupId: JSCategories groups: - "category:JavaScript and TypeScript/ES2015 migration aids" - groupId: PHPInspections inspections: # Inspection IDs - PhpDeprecationInspection - PhpReturnDocTypeMismatchInspection inspections: # Group invocation - group: InspectionsToInclude enabled: true # Enable the InspectionsToInclude group - inspection: PhpNonCompoundUseInspection severity: WARNING # Overriding the severity level for PhpNonCompoundUseInspection - inspection: MissortedModifiers options: m_requireAnnotationsFirst: false # Overriding the configuration option

このサンプルは、いくつかのノードで構成されています。

セクション

説明

baseProfile

プロファイル構成の基礎となるプロファイル

name

インスペクションプロファイルの名前

include

既存のファイルベースのプロファイルをプロファイルに含める

groups

プロファイルに含めるか除外する必要があるインスペクショングループ

inspections

baseProfile に適用された変更のリスト。これらの変更はグループまたは単一のインスペクションに適用できます

基本プロファイル

baseProfile ブロックを使用すると、プロファイル構成の基礎となるプロファイルを指定できます。次の値を受け入れることができます。

baseProfile

説明

Default

JetBrains IDE から取得されたデフォルトのプロファイル

Project Default

プロファイルは基本的に Default に似ていますが、.idea/inspectionProfiles/Project_Default.xml ファイルに保存されたユーザーの変更が含まれています。

Custom profile name

.idea/inspectionProfiles ディレクトリに含まれる XML または YAML プロファイルの任意の名前

qodana.starter

デフォルトの Qodana プロファイル、qodana.recommended プロファイルのサブセット

qodana.recommended

JetBrains IDE のデフォルトプロファイルを実装するデフォルトの Qodana プロファイル

empty

インスペクションの重大度とパラメーターは Project Default から取得されますが、インスペクションは含まれません。empty を使用すると、プロファイルを最初から作成できます

このパラメーターが欠落している場合、Qodana は Project Default プロファイルを採用するため、カスタムプロファイルに適用されるすべての設定は、Project Default に含まれるそのような設定をオーバーライドします。

名前

プロファイルの任意の名前。

name: "Name of your profile"

グループ

groups ブロックは、ユーザー定義グループのリストです。ここでは、インスペクションカテゴリと単一のインスペクションを組み合わせて、 inspections ブロックでそれらの使用箇所を構成できます。

各グループ定義では、他のグループまたは単一のインスペクションを含めたり除外したりできます。

感嘆符文字 (!) を使用して、グループまたはカテゴリを否定できます。例: 含まれるグループ内の特定のカテゴリの使用を除外できます。

ユーザーが定義した EnabledInspections グループを含むサンプルを次に示します。

groups: - groupId: EnabledInspections groups: - "category:Java/Probable bugs" inspections: - RedundantIf

このサンプルには次のプロパティが含まれています。

プロパティ

説明

groupId

グループの ID

inspections

このグループに含まれるインスペクションと除外されるインスペクションのリスト

groups

このグループに含まれるグループと除外されるグループのリスト

groups.groupId

一意のグループ識別子。

- groupId: IncludedInspections

2 つのグループが同じ groupId で定義されている場合、ファイル内で見つかった最新のグループが使用されます。インクルードされるファイルに含まれる設定は、現在のファイルに配置される設定よりも前に考慮されるため、このルールはインクルードされるすべてのファイルにも適用されます。

groups.inspections

グループに含まれるインスペクションのリスト。

inspections: - RedundantIf - UnnecessaryLocalVariable

groups.groups

使用可能な感嘆符文字 (!) を含むグループ ID のリスト:

groups: - "ALL" - "category:Java/Probable bugs" - "IncludedInspections" - "!ExcludedInspections" - "severity:WEAK WARNING"

ここで、groups にはいくつかの値がリストされています。

groupId

説明

ALL

インスペクションをすべて含めます。それに加えて、LOCAL を使用してローカルで利用可能なインスペクションを使用してコードをインスペクションしたり、GLOBAL を使用して JetBrains IDE のコードのインスペクションアクションを使用してコードをインスペクションしたりすることもできます。

category:Java/Probable bugs

category:categoryname 表記におけるインスペクションカテゴリの名前は、JetBrains IDE のエディター | 設定 | インスペクションセクションの名前と一致します。

IncludedInspections

既存のユーザー定義グループの名前、または含まれているプロファイルのグループの名前

!ExcludedInspections

ユーザー定義または別のプロファイルに含まれている既存の ExcludedInspections インスペクショングループを無効にします

severity:WEAK WARNING

インスペクションを特定の重大度レベルで含めるか除外します。重大度の値は Default プロファイルから取得されるため、Qodana はプロファイルに加えられた変更を認識しません。

デフォルトでは、Qodana は、次の表に示す JetBrains IDE から継承した重大度レベルを使用します。

IDE の重大度

SARIF 重大度

コダナレポート重大度

ERROR

ERROR

クリティカル

警告

警告

弱い警告

適度

TYPO

INFORMATION

情報

OTHER

情報

インスペクション

inspections を使用すると、次のことが可能になります。

  • 特定のグループまたはインスペクションを有効または無効にする

  • これらの設定を適用する順序を定義します

  • 特定のグループまたはインスペクションによって無視されるパスまたはスコープを定義します

  • 特定のグループまたはインスペクションの重大度レベルを変更する

  • インスペクションオプションを設定する

inspections: - group: InspectionGroup - inspection: JavadocReference severity: WARNING - group: ALL ignore: - "vendor/**" - "scope#file[*test*]:src/*" - group: DisabledInspections enabled: false - inspection: MissortedModifiers options: m_requireAnnotationsFirst: false

このサンプルには、いくつかのプロパティが含まれています。

プロパティ

説明

group

埋め込みグループまたはユーザー定義グループの groupId プロパティからのグループの ID

inspection

インスペクションの ID

severity

インスペクションのグループまたは単一のインスペクションに割り当てられる重大度レベル。例: ERROR の代わりに WARNING を指定できます

ignore

インスペクション中に無視されるグロブパターン(英語)スコープを使用するパスのリスト

enabled

グループまたはインスペクションをプロファイルで有効にするかどうかを指定します。true または false のいずれかを受け入れます

options

特定のインスペクションに対して構成できるオプションのリスト

包含

含まれるプロファイルへの相対パスのリストが含まれます。

include: - "firstprofile.yaml" - "relative/path/to/anotherprofile.yaml"

include ブロックは baseProfile とは関係ありません。baseProfile に値が含まれていない場合は、Default に設定されます。

デフォルトプロファイルを表示するには、JetBrains IDE で設定 | エディター | インスペクションに移動し、プロファイルドロップダウンセレクターで Default プロファイルを選択します。

ファイルの内容は出現順に含まれるため、プロファイルの一部になります。これは、含まれるファイルの設定が、カスタムプロファイルで指定された設定よりも前に使用されることを意味します。

サンプル

foo.yaml および bar.yaml プロファイルがあると仮定します。

foo.yaml プロファイルは Inspection1Inspection2Inspection3 インスペクションを有効にします。

inspections: - inspection: Inspection1 enabled: true - inspection: Inspection2 enabled: true - inspection: Inspection3 enabled: true

bar.yaml プロファイルは、Inspection1 インスペクションを無効にします。

inspections: - inspection: Inspection1 enabled: false

これら 2 つのファイルをカスタムプロファイルに含めて、Inspection2 を無効にすることができます。

include: - "foo.yaml" - "bar.yaml" inspections: - inspection: Inspection2 enabled: false

この場合、Qodana によって読み取られる有効なプロファイル構成は次のようになります。

inspections: - inspection: Inspection1 enabled: false # "bar.yaml" was included later than "foo.yaml" - inspection: Inspection2 enabled: false # it was applied in the custom profile last - inspection: Inspection3 enabled: true

構成例

ここでは、プロファイル構成のいくつかの例を見つけることができます。プロファイルを設定するセクションでは、コードをインスペクションしながらプロファイルを実行する方法について説明します。

インスペクションを除外する

このサンプルは、PHP 用の Qodana リンターから PhpDeprecationInspection インスペクションを除外する方法を示しています。

name: "PHP/General without PhpDeprecationInspection" baseProfile: qodana.starter inspections: - inspection: PhpDeprecationInspection enabled: false

あるいは、groups を使用して PhpDeprecationInspection インスペクションを除外することもできます。

name: "PHP/General without PhpDeprecationInspection" baseProfile: qodana.starter groups: - groupId: Inspection inspections: - PhpDeprecationInspection # Specify the PhpDeprecationInspection inspection inspections: - group: Inspection enabled: false # Disable the PhpDeprecationInspection inspection

除外対象パス

ignore ブロックを使用すると、コードのインスペクション中に特定のスコープとパスを無視できます。

以下のサンプルでは、vendor/** 値は、プロジェクトルートに含まれる vendor ディレクトリの内容を無視するグロブパターン(英語)を使用しています。

スコープ定義 scope#file:*.js:testData//* は、testData/ ディレクトリに再帰的に含まれる .js 拡張子を持つすべてのファイルを無視します。

name: "Ignoring paths" inspections: - inspection: NpmUsedModulesInstalled ignore: - "vendor/**" # Ignore a path - group: "category:JavaScript and TypeScript/General" ignore: - "scope#file:*.js:testData//*" # Ignore a scope

プロファイルを最初から作成する

baseProfile を使用して、この構成では空のプロファイルを定義し、JVM 用 Qodana リンターからの Java/Data flow インスペクショングループのみを含めます。

name: "Java/Data flow only" baseProfile: empty inspections: - group: "category:Java/Data flow" enabled: true # Enable the 'Java/Data flow' category

baseProfile の代わりに、 groups プロパティで ALL を使用できます。

name: "Java/Data flow only" groups: - groupId: ExcludedInspections groups: - "ALL" - groupId: IncludedInspections groups: - "category:Java/Data flow" # Specify the 'Java/Data flow' category inspections: - group: ExcludedInspections enabled: false # Disable all inspections - group: IncludedInspections enabled: true # Enable the 'Java/Data flow' category

既存のプロファイルを上書きする

.NET 用 Qodana リンターに関連しないインスペクションカテゴリを qodana.starter (英語) プロファイルから除外できます。

name: "My custom profile" baseProfile: qodana.starter # Use the 'qodana.starter' profile groups: - groupId: ExcludedInspections groups: - "category:Java" - "category:Kotlin" - "category:JVM languages" - "category:Spring" - "category:CDI (Contexts and Dependency Injection)" - "category:Bean Validation" - "category:Reactive Streams" - "category:RegExp" - "category:PHP" - "category:Go" - "category:Python" - "category:General" - "category:TOML" inspections: - group: ExcludedInspections enabled: false

重大度でフィルタリングする

このサンプルには、Java コードのインスペクション中に、重大度レベルが WEAK WARNING のすべてのインスペクションが含まれています。

name: "My custom profile" groups: - groupId: IncludedInspections groups: - "category:Java" - "severity:WEAK WARNING" inspections: - group: IncludedInspections enabled: true

特定のインスペクションに重大度レベルを適用することもできます。

name: "My custom profile" inspections: - inspection: JavadocReference severity: WARNING

インスペクションオプションを設定する

いくつかのインスペクションは構成オプションを提供します。利用可能なオプションのリストは GitHub(英語) で確認できます。

例: MissingOverrideAnnotation インスペクションの場合、ignoreObjectMethods および ignoreAnonymousClassMethods オプションが見つかります。

<inspection_tool class="MissingOverrideAnnotation" enabled="true" level="INFORMATION" enabled_by_default="true"> <option name="ignoreObjectMethods" value="true" /> <option name="ignoreAnonymousClassMethods" value="false" /> </inspection_tool>

これは、プロファイル内のこれらのオプションをオーバーライドする方法です。

name: "My custom profile" # Profile name baseProfile: qodana.recommended inspections: - inspection: MissingOverrideAnnotation options: ignoreObjectMethods: false ignoreAnonymousClassMethods: true

次のステップ

プロファイルを構成した後、プロファイルを設定するセクションの推奨事項に従って、そのプロファイルを使用して Qodana を実行できます。

関連ページ:

スコープ言語構文リファレンス

スコープ言語を使用して、プロジェクトスコープ (ファイル、ディレクトリ、サブディレクトリのセット) を指定できます。クラスのセット:単一のクラスは、たとえばクラス名によって定義されます:、サブパッケージに拒否されない、パッケージ内のすべてのクラスのセットは、たとえば、ドットの後のアスタリスクで定義されます。サブパッケージの内容を含むパッケージ内のすべてのクラスのセットは、ダブルドットの後のアスタリスクで定義されます(例:)。ファイルのセット:単一のファイルを追加するには、ファイル名を使用する

SARIF 出力

Qodana レポートは SARIF 仕様に従ってフォーマットされ、JSON ファイルに含まれます。SARIF の Qodana 実装は、一般的な形式規則に従いますが、プロパティバッグに含まれるいくつかのカスタムプロパティも指定します。レポートの構造:Qodana によって生成されるレポートの構造は次のとおりです。{ "version": "2.1.0", "runs": [ { "tool": {...}, "invocations": [...], "language": "en-US",...

インスペクションレポート

Qodana を使用すると、ローカルまたは Qodana クラウドで、インタラクティブでユーザーフレンドリーな形式でインスペクションレポートを確認できます。各レポートには次のタブが含まれています。実際の問題は、Qodana が最新のインスペクション中に検出した問題を明らかにします、ベースラインには、ベースラインとしてマークされ、それ以降修正されていない問題がリストされます。構成により、将来の使用に備えて Qodana を構成できます、ライセンス監査は

インスペクションプロファイル

インスペクションプロファイルは、インスペクション、これらのインスペクションが分析するファイルスコープ、およびインスペクションの重大度を定義します。このセクションでは、既存の Qodana プロファイルを使用する方法、独自のプロファイルを作成する方法、Qodana を使用してプロジェクトを分析するためのプロファイルを設定する方法について説明します。既存の Qodana プロファイル:すぐに使用できる Qodana プロファイルは次のとおりです。プロファイルのサブセット。Qodana ではデフォル...