moz-fluent-linter 0.4.6__py3-none-any.whl → 0.4.8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
fluent_linter/__init__.py CHANGED
@@ -1 +1 @@
1
- version = "0.4.6"
1
+ version = "0.4.8"
fluent_linter/linter.py CHANGED
@@ -5,15 +5,19 @@
5
5
  # This script is largely based on the Fluent Linter used in mozilla-central
6
6
  # https://firefox-source-docs.mozilla.org/code-quality/lint/linters/fluent-lint.html
7
7
 
8
- from fluent.syntax import ast, parse, serializer, visitor
9
- from html.parser import HTMLParser
10
8
  import argparse
11
9
  import bisect
12
10
  import os
13
11
  import re
14
12
  import sys
13
+
14
+ from html.parser import HTMLParser
15
+
15
16
  import yaml
16
17
 
18
+ from fluent.syntax import ast, parse, serializer, visitor
19
+
20
+
17
21
  try:
18
22
  from fluent_linter import version
19
23
  except Exception:
@@ -160,31 +164,42 @@ class Linter(visitor.Visitor):
160
164
  f" hard-coded brand names ({', '.join(found_brands)})",
161
165
  )
162
166
 
163
- if self.apostrophe_re.search(cleaned_str):
164
- if not self.exclude_message("TE01", message_id):
165
- self.add_error(
166
- node,
167
- message_id,
168
- "TE01",
169
- "Strings with apostrophes should use foo\u2019s instead of foo's.",
170
- )
171
- if self.incorrect_apostrophe_re.search(cleaned_str):
172
- if not self.exclude_message("TE02", message_id):
173
- self.add_error(
174
- node,
175
- message_id,
176
- "TE02",
177
- "Strings with apostrophes should use foo\u2019s instead of foo\u2018s.",
178
- )
179
- if self.single_quote_re.search(cleaned_str):
180
- if not self.exclude_message("TE03", message_id):
181
- self.add_error(
182
- node,
183
- message_id,
184
- "TE03",
185
- "Single-quoted strings should use Unicode \u2018foo\u2019 instead of 'foo'.",
186
- )
187
- if self.double_quote_re.search(cleaned_str):
167
+ if (
168
+ self.config.get("TE01", {}).get("enabled", True)
169
+ and self.apostrophe_re.search(cleaned_str)
170
+ and not self.exclude_message("TE01", message_id)
171
+ ):
172
+ self.add_error(
173
+ node,
174
+ message_id,
175
+ "TE01",
176
+ "Strings with apostrophes should use foo\u2019s instead of foo's.",
177
+ )
178
+ if (
179
+ self.config.get("TE02", {}).get("enabled", True)
180
+ and self.incorrect_apostrophe_re.search(cleaned_str)
181
+ and not self.exclude_message("TE02", message_id)
182
+ ):
183
+ self.add_error(
184
+ node,
185
+ message_id,
186
+ "TE02",
187
+ "Strings with apostrophes should use foo\u2019s instead of foo\u2018s.",
188
+ )
189
+ if (
190
+ self.config.get("TE03", {}).get("enabled", True)
191
+ and self.single_quote_re.search(cleaned_str)
192
+ and not self.exclude_message("TE03", message_id)
193
+ ):
194
+ self.add_error(
195
+ node,
196
+ message_id,
197
+ "TE03",
198
+ "Single-quoted strings should use Unicode \u2018foo\u2019 instead of 'foo'.",
199
+ )
200
+ if self.config.get("TE04", {}).get(
201
+ "enabled", True
202
+ ) and self.double_quote_re.search(cleaned_str):
188
203
  # Ignore parameterized terms and other functions
189
204
  for regex in self.ftl_syntax_re:
190
205
  cleaned_str = regex.sub("", cleaned_str)
@@ -198,15 +213,18 @@ class Linter(visitor.Visitor):
198
213
  "TE04",
199
214
  'Double-quoted strings should use Unicode \u201cfoo\u201d instead of "foo".',
200
215
  )
201
- if self.ellipsis_re.search(cleaned_str):
202
- if not self.exclude_message("TE05", message_id):
203
- self.add_error(
204
- node,
205
- message_id,
206
- "TE05",
207
- "Strings with an ellipsis should use the Unicode \u2026 character"
208
- " instead of three periods",
209
- )
216
+ if (
217
+ self.config.get("TE05", {}).get("enabled", True)
218
+ and self.ellipsis_re.search(cleaned_str)
219
+ and not self.exclude_message("TE05", message_id)
220
+ ):
221
+ self.add_error(
222
+ node,
223
+ message_id,
224
+ "TE05",
225
+ "Strings with an ellipsis should use the Unicode \u2026 character"
226
+ " instead of three periods",
227
+ )
210
228
 
211
229
  def generic_visit(self, node):
212
230
  node_name = type(node).__name__
@@ -418,9 +436,9 @@ class Linter(visitor.Visitor):
418
436
  and not self.config["PS01"]["disabled"]
419
437
  and type(node.expression) not in [ast.SelectExpression]
420
438
  ):
421
- if type(node.expression) == ast.VariableReference:
439
+ if isinstance(node.expression, ast.VariableReference):
422
440
  placeable_name = f"${node.expression.id.name}"
423
- elif type(node.expression) == ast.TermReference:
441
+ elif isinstance(node.expression, ast.TermReference):
424
442
  placeable_name = f"-{node.expression.id.name}"
425
443
  else:
426
444
  placeable_name = node.expression.id.name
@@ -455,7 +473,7 @@ class Linter(visitor.Visitor):
455
473
  # Store the variable used for the SelectExpression, excluding functions
456
474
  # like PLATFORM()
457
475
  if (
458
- type(node.selector) == ast.VariableReference
476
+ isinstance(node.selector, ast.VariableReference)
459
477
  and node.selector.id.name not in self.state["variables"]
460
478
  ):
461
479
  self.state["variables"].append(node.selector.id.name)
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: moz-fluent-linter
3
- Version: 0.4.6
3
+ Version: 0.4.8
4
4
  Summary: Linter package used to check Fluent files
5
5
  Home-page: https://github.com/mozilla-l10n/moz-fluent-linter
6
6
  Author: Francesco Lodolo
@@ -15,9 +15,10 @@ Classifier: Topic :: Software Development :: Localization
15
15
  Requires-Python: >=3.7
16
16
  Description-Content-Type: text/markdown
17
17
  License-File: LICENSE
18
- Requires-Dist: fluent.syntax <0.19,>=0.18.0
18
+ Requires-Dist: fluent.syntax~=0.19.0
19
19
  Requires-Dist: pyyaml
20
20
  Requires-Dist: six
21
+ Dynamic: license-file
21
22
 
22
23
  # Fluent Linter
23
24
 
@@ -41,7 +42,7 @@ Using [pre-commit](https://pre-commit.com/), add this to the `.pre-commit-config
41
42
  ```yaml
42
43
  repos:
43
44
  - repo: https://github.com/mozilla-l10n/moz-fluent-linter
44
- rev: v0.4.6
45
+ rev: v0.4.8
45
46
  hooks:
46
47
  - id: fluent_linter
47
48
  files: \.ftl$
@@ -0,0 +1,8 @@
1
+ fluent_linter/__init__.py,sha256=U86LejrmMsdC6N-YT7_w8TPLE0rJkGNw9YkhBt378b8,18
2
+ fluent_linter/linter.py,sha256=onOdmqgbj2f9yCHWFHDtT30SK8VJWwG4bv40qYrCv2I,25551
3
+ moz_fluent_linter-0.4.8.dist-info/licenses/LICENSE,sha256=HyVuytGSiAUQ6ErWBHTqt1iSGHhLmlC8fO7jTCuR8dU,16725
4
+ moz_fluent_linter-0.4.8.dist-info/METADATA,sha256=SjtC23VlGZZ5BTT3ajsYZ2zFxHjbhCoSwVt-ovSaIpU,2134
5
+ moz_fluent_linter-0.4.8.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
6
+ moz_fluent_linter-0.4.8.dist-info/entry_points.txt,sha256=-7bz7GIrEJyjG8EUMDKgS6FudRSpGZ9kf7jKQCp1MEg,62
7
+ moz_fluent_linter-0.4.8.dist-info/top_level.txt,sha256=UZi4ExOI1JTsfp5RPbNYAvFFLLZdzKnzPaCbcaEK_d0,14
8
+ moz_fluent_linter-0.4.8.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.43.0)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,8 +0,0 @@
1
- fluent_linter/__init__.py,sha256=DWNNbWBv-hyqVy76bKbnHWaDUbqL0BOtdkPSV_88dx0,18
2
- fluent_linter/linter.py,sha256=d6s8I4PWIeIOgu-WwfvB2wHDLF0WKm3lOMszerdfqf8,25204
3
- moz_fluent_linter-0.4.6.dist-info/LICENSE,sha256=HyVuytGSiAUQ6ErWBHTqt1iSGHhLmlC8fO7jTCuR8dU,16725
4
- moz_fluent_linter-0.4.6.dist-info/METADATA,sha256=q44LxVa65ySt0SHSkFyTGu7y6CsuywDkCR9HMP9-qwg,2119
5
- moz_fluent_linter-0.4.6.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
6
- moz_fluent_linter-0.4.6.dist-info/entry_points.txt,sha256=-7bz7GIrEJyjG8EUMDKgS6FudRSpGZ9kf7jKQCp1MEg,62
7
- moz_fluent_linter-0.4.6.dist-info/top_level.txt,sha256=UZi4ExOI1JTsfp5RPbNYAvFFLLZdzKnzPaCbcaEK_d0,14
8
- moz_fluent_linter-0.4.6.dist-info/RECORD,,