mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-15 02:59:33 +07:00
update RegExp inspection descriptions with examples
GitOrigin-RevId: 1daa0f68ede1036d134127cdacd0b61e5d438ca8
This commit is contained in:
committed by
intellij-monorepo-bot
parent
a99d1835ba
commit
c50a102e50
@@ -1,14 +1,18 @@
|
||||
<!--
|
||||
~ Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
-->
|
||||
|
||||
<html>
|
||||
<body>
|
||||
Reports anonymous capturing groups and numeric back references in a RegExp.
|
||||
These are only reported when the RegExp dialect supports named group and named group references.
|
||||
Named groups and named back references improve code readability and are recommended to use instead.
|
||||
When a capture is not needed, matching can be more performant and use less memory by using a non-capturing group,
|
||||
i.e. <b>(?:xxx)</b> instead of <b>(xxx)</b>.
|
||||
i.e. <code>(?:xxx)</code> instead of <code>(xxx)</code>.
|
||||
<p><b>Example:</b></p>
|
||||
<pre><code>
|
||||
(\d\d\d\d)\1
|
||||
</code></pre>
|
||||
<p>A better regex pattern could look like this:</p>
|
||||
<pre><code>
|
||||
(?<quad>\d\d\d\d)\k<quad>
|
||||
</code></pre>
|
||||
<!-- tooltip end -->
|
||||
<p><small>New in 2017.2</small>
|
||||
</body>
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
<!--
|
||||
~ Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
-->
|
||||
|
||||
<html>
|
||||
<body>
|
||||
Reports duplicate branches in a RegExp alternation. For example <code>(a|b|a)</code>.
|
||||
Reports duplicate branches in a RegExp alternation.
|
||||
Duplicate branches slow down matching and obscure the intent of the expression.
|
||||
<p><b>Example:</b></p>
|
||||
<pre><code>
|
||||
(alpha|bravo|charlie|alpha)
|
||||
</code></pre>
|
||||
<p>After the quick-fix is applied:</p>
|
||||
<pre><code>
|
||||
(alpha|bravo|charlie)
|
||||
</code></pre>
|
||||
<!-- tooltip end -->
|
||||
<p><small>New in 2017.1</small>
|
||||
</body>
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports duplicate characters inside a RegExp character class. For example <code>[++]</code>.
|
||||
Reports duplicate characters inside a RegExp character class.
|
||||
Duplicate characters are unnecessary and can be removed without changing the semantics of the regex.
|
||||
<p><b>Example:</b></p>
|
||||
<pre><code>
|
||||
[aabc]
|
||||
</code></pre>
|
||||
<p>After the quick-fix is applied:</p>
|
||||
<pre><code>
|
||||
[abc]
|
||||
</code></pre>
|
||||
<!-- tooltip end -->
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,12 +1,16 @@
|
||||
<!--
|
||||
~ Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
-->
|
||||
|
||||
<html>
|
||||
<body>
|
||||
Reports empty branches in a RegExp alternation. For example:<br> <code>a<b>||</b>b</code>
|
||||
<p>An empty branch will only match the empty string, and in most cases that is not what is desired.
|
||||
Reports empty branches in a RegExp alternation.
|
||||
An empty branch will only match the empty string, and in most cases that is not what is desired.
|
||||
This inspection will not report a single empty branch at the start or the end of an alternation.
|
||||
<p><b>Example:</b></p>
|
||||
<pre><code>
|
||||
(alpha||bravo)
|
||||
</code></pre>
|
||||
<p>After the quick-fix is applied:</p>
|
||||
<pre><code>
|
||||
(alpha|bravo)
|
||||
</code></pre>
|
||||
<!-- tooltip end -->
|
||||
<p><small>New in 2017.2</small>
|
||||
</body>
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
<!--
|
||||
~ Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
-->
|
||||
|
||||
<html>
|
||||
<body>
|
||||
Reports the escaped meta characters, e.g. <b><code>\.</code></b>.
|
||||
Reports the escaped meta characters.
|
||||
Some RegExp coding styles specify that meta characters should be placed inside a character class,
|
||||
to make the regular expression easier to understand.
|
||||
For example the regex <b><code>\d+\.\d+</code></b> would be written as <code>\d+[.]\d+</code>.
|
||||
This inspection does not warn about the meta character <b><code>[</code></b>, <b><code>]</code></b> and <b><code>^</code></b>,
|
||||
This inspection does not warn about the meta character <code>[</code>, <code>]</code> and <code>^</code>,
|
||||
because those would need additional escaping inside a character class.
|
||||
<p><b>Example:</b></p>
|
||||
<pre><code>
|
||||
\d+\.\d+
|
||||
</code></pre>
|
||||
<p>After the quick-fix is applied:</p>
|
||||
<pre><code>
|
||||
\d+[.]\d+
|
||||
</code></pre>
|
||||
<!-- tooltip end -->
|
||||
<p><small>New in 2017.1</small>
|
||||
</body>
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
<!--
|
||||
~ Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
-->
|
||||
|
||||
<html>
|
||||
<body>
|
||||
Reports octal escapes, which are easily confused with back references.
|
||||
Use hexadecimal escapes to avoid confusion.
|
||||
<p><b>Example:</b></p>
|
||||
<pre><code>
|
||||
\07
|
||||
</code></pre>
|
||||
<p>After the quick-fix is applied:</p>
|
||||
<pre><code>
|
||||
\x07
|
||||
</code></pre>
|
||||
<!-- tooltip end -->
|
||||
<p><small>New in 2017.1</small>
|
||||
</body>
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
<!--
|
||||
~ Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
-->
|
||||
|
||||
<html>
|
||||
<body>
|
||||
Reports character escapes that are replaceable with the unescaped character without a change in meaning.
|
||||
Note that inside the square brackets of a character class, many escapes are unnecessary that would be necessary outside of a character class.
|
||||
For example the regex <b><code>[\.]</code></b> is identical to <b><code>[.]</code></b>
|
||||
<p><b>Example:</b></p>
|
||||
<pre><code>
|
||||
\-\;[\.]
|
||||
</code></pre>
|
||||
<p>After the quick-fix is applied:</p>
|
||||
<pre><code>
|
||||
-;[.]
|
||||
</code></pre>
|
||||
<!-- tooltip end -->
|
||||
<p><small>New in 2017.3</small>
|
||||
</body>
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports unnecessary nested character classes.
|
||||
For example <code>[a-c[x-z]]</code>, which is equivalent too <code>[a-cx-z]</code>.
|
||||
<p><b>Example:</b></p>
|
||||
<pre><code>
|
||||
[a-c[x-z]]
|
||||
</code></pre>
|
||||
<p>After the quick-fix is applied:</p>
|
||||
<pre><code>
|
||||
[a-cx-z]
|
||||
</code></pre>
|
||||
<!-- tooltip end -->
|
||||
<p><small>New in 2020.2</small>
|
||||
</body>
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
<!--
|
||||
~ Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
-->
|
||||
|
||||
<html>
|
||||
<body>
|
||||
Reports multiple consecutive spaces in a RegExp.
|
||||
Because spaces are not visible by default, it can be hard to see how many spaces are required.
|
||||
The RegExp can be made more clear by replacing the consecutive spaces with a single space and a counted quantifier.
|
||||
<p><b>Example:</b></p>
|
||||
<pre><code>
|
||||
( )
|
||||
</code></pre>
|
||||
<p>After the quick-fix is applied:</p>
|
||||
<pre><code>
|
||||
( {5})
|
||||
</code></pre>
|
||||
<!-- tooltip end -->
|
||||
<p>
|
||||
<small>New in 2017.1</small>
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports single char alternation (e.g. <b><code>a|b|c|d</code></b>) in a RegExp.
|
||||
It is simpler to use a character class (<b><code>[abcd]</code></b>) instead.
|
||||
This usually also provides slightly better matching performance.
|
||||
Reports single char alternation in a RegExp.
|
||||
It is simpler to use a character class instead.
|
||||
This may also provide better matching performance.
|
||||
<p><b>Example:</b></p>
|
||||
<pre><code>
|
||||
a|b|c|d
|
||||
</code></pre>
|
||||
<p>After the quick-fix is applied:</p>
|
||||
<pre><code>
|
||||
[abcd]
|
||||
</code></pre>
|
||||
<!-- tooltip end -->
|
||||
<p>
|
||||
<small>New in 2017.1</small>
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
<!--
|
||||
~ Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
-->
|
||||
|
||||
<html>
|
||||
<body>
|
||||
Reports <code>^</code> or <code>\A</code> anchors not at the beginning of the pattern and
|
||||
<code>$</code>, <code>\Z</code> or <code>\z</code> anchors not at the end of the pattern.
|
||||
In the wrong position these RegExp anchors prevent the pattern from matching anything.
|
||||
In case of the <code>^</code> and <code>$</code> anchors, most likely the literal character was meant and the escape forgotten.
|
||||
<p><b>Example:</b></p>
|
||||
<pre><code>
|
||||
(Price $10)
|
||||
</code></pre>
|
||||
<!-- tooltip end -->
|
||||
<p>
|
||||
<small>New in 2018.1</small>
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports unnecessary non-capturing groups.
|
||||
For example<br>
|
||||
<code>Everybody be cool, (?:this) is a robbery!</code><br>
|
||||
is equivalent too<br>
|
||||
<code>Everybody be cool, this is a robbery!</code>.
|
||||
Reports unnecessary non-capturing groups, which have no influence on the match result.
|
||||
<p><b>Example:</b></p>
|
||||
<pre><code>
|
||||
Everybody be cool, (?:this) is a robbery!
|
||||
</code></pre>
|
||||
<p>After the quick-fix is applied:</p>
|
||||
<pre><code>
|
||||
Everybody be cool, this is a robbery!
|
||||
</code></pre>
|
||||
<!-- tooltip end -->
|
||||
<p><small>New in 2021.1</small>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user