質問

PHPファイルが分析されたときにコードの一部を無視することができます PHP_CodeSniffer?

役に立ちましたか?

解決

はい、@codingStandArdsignorestartおよび@codingStandardsignoreEndアノテーションで可能です

<?php
some_code();
// @codingStandardsIgnoreStart
this_will_be_ignored();
// @codingStandardsIgnoreEnd
some_other_code();

また、説明されています ドキュメントで。

他のヒント

組み合わせを使用できます。 @codingStandardsIgnoreStart@codingStandardsIgnoreEnd または使用することができます @codingStandardsIgnoreLine.

例:

<?php

command1();
// @codingStandardsIgnoreStart
command2(); // this line will be ignored by Codesniffer
command3(); // this one too
command4(); // this one too
// @codingStandardsIgnoreEnd

command6();

// @codingStandardsIgnoreLine
command7(); // this line will be ignored by Codesniffer

バージョン3.2.0の前に、PHP_CODESNIFFERは異なる構文を使用して、ファイルからコードの一部を無視しました。を参照してください 反veeranna'sマーティン・ヴセッカの 回答。古い構文はバージョン4.0で削除されます

PHP_CODESNIFFERが使用されています // phpcs:disable// phpcs:enable ファイルの一部を無視するためのコメント // phpcs:ignore 1つの行を無視します。

現在、特定のエラーメッセージコード、スニフ、スニフのカテゴリ、またはコーディング標準全体のみを無効または有効にすることも可能です。コメントの後に指定する必要があります。必要に応じて、スニフが無効になっている理由を説明するメモを追加できます。 -- セパレーター。

<?php

/* Example: Ignoring parts of file for all sniffs */
$xmlPackage = new XMLPackage;
// phpcs:disable
$xmlPackage['error_code'] = get_default_error_code_value();
$xmlPackage->send();
// phpcs:enable

/* Example: Ignoring parts of file for only specific sniffs */
// phpcs:disable Generic.Commenting.Todo.Found
$xmlPackage = new XMLPackage;
$xmlPackage['error_code'] = get_default_error_code_value();
// TODO: Add an error message here.
$xmlPackage->send();
// phpcs:enable

/* Example: Ignoring next line */
// phpcs:ignore
$foo = [1,2,3];
bar($foo, false);

/* Example: Ignoring current line */
$foo = [1,2,3]; // phpcs:ignore
bar($foo, false);

/* Example: Ignoring one line for only specific sniffs */
// phpcs:ignore Squiz.Arrays.ArrayDeclaration.SingleLineNotAllowed
$foo = [1,2,3];
bar($foo, false);

/* Example: Optional note */ 
// phpcs:disable PEAR,Squiz.Arrays -- this isn't our code
$foo = [1,2,3];
bar($foo,true);
// phpcs:enable PEAR.Functions.FunctionCallSignature -- check function calls again
bar($foo,false);
// phpcs:enable -- this is out code again, so turn everything back on

詳細については、参照してください php_codesnifferのドキュメント.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top