Metadata-Version: 2.5
Name: matra-lint
Version: 0.1.0
Summary: Find code that breaks text written in Indian scripts: shattered words, rejected names, split syllables.
Project-URL: Homepage, https://github.com/RaktimChandra/matra-lint
Author-email: Raktim Chandra <raktimchandra26@gmail.com>
License-Expression: MIT
License-File: LICENSE
Keywords: bengali,devanagari,grapheme,hindi,i18n,indic,linter,sarif,tamil,unicode
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: Bengali
Classifier: Natural Language :: Hindi
Classifier: Natural Language :: Tamil
Classifier: Natural Language :: Telugu
Classifier: Topic :: Software Development :: Quality Assurance
Classifier: Topic :: Text Processing :: Linguistic
Requires-Python: >=3.10
Requires-Dist: regex>=2023.0
Provides-Extra: test
Requires-Dist: pytest>=8; extra == 'test'
Description-Content-Type: text/markdown

# matra

**Find code that breaks text written in Indian scripts.**

Most text code is written and tested in English. Run it on Hindi, Bengali, Tamil or any of India's scripts and it fails quietly: words fall apart, real names are rejected, and truncated text ends in half a syllable. The cause is almost always the same. Indian scripts write vowels as **combining marks** (matras) attached to consonants, and ASCII-minded code does not count those marks as letters.

`matra` finds that code in JavaScript/TypeScript, Python, Go and Rust, shows the word it breaks, and gives the fix. `matra fuzz` then proves it by running your own functions on real words in 11 scripts.

```
$ matra demo
What ASCII-minded Python does to Indian-script text:

  re.findall(r'\w+', 'हिंदी')                -> ['ह', 'द']
  'हिंदी'.isalpha()                         -> False
  re.fullmatch(r'[A-Za-z ]+', 'प्रिया')        -> None
  'क्षमा'[:2]                               -> 'क्'
  'हिंदी'[::-1]                             -> 'ीदंिह'
```

None of these is exotic. `'हिंदी'.isalpha()` is `False`, and so is `isalpha()` for every word with a vowel sign in Tamil, Bengali, Telugu, Punjabi and the rest. So a name check built on it rejects every name written in an Indian script. In JavaScript, `/\w+/u` matches nothing at all in `'हिंदी'`, and `\b` finds no word boundary in `'தமிழ்'`.

## Install

```
pip install git+https://github.com/RaktimChandra/matra-lint
```

## Use

```
matra check .                       # scan a project
matra check src --min-confidence medium
matra check . --format sarif > matra.sarif   # GitHub code scanning
matra rules                         # every rule with its evidence
matra fuzz myapp.text:truncate --kind truncate
```

`check` exits with 1 when it finds something, so it can gate CI. Silence a line with `# matra: ignore` or `// matra: ignore[MAT006]`, or a whole file (fixtures, test data) with `matra: ignore-file` in its first 10 lines.

## Rules

Every rule's evidence is checked by the test suite against the real runtime, not assumed.

| Rule | Languages | Confidence | Flags | Breaks because |
| --- | --- | --- | --- | --- |
| MAT001 ascii-word-class | JS/TS, Python, Go | medium | `\w`, `\b` in a regex | `re.findall(r'\w+', 'हिंदी') == ['ह', 'द']`; in JS `/\w+/u` finds nothing |
| MAT002 letters-without-marks | all | high | `[\p{L}...]+` with no `\p{M}` | `'हिंदी'.match(/[\p{L}]+/gu)` gives `['ह', 'द']` |
| MAT003 isalpha-rejects-indic | Python | high | `.isalpha()`, `.isalnum()` | `False` for every word with a vowel sign |
| MAT004 go-isletter-without-ismark | Go | medium | `unicode.IsLetter` with no `IsMark` in the file | vowel signs are category M, not L |
| MAT005 ascii-only-name-pattern | all | medium | `[A-Za-z]` on a name, city or address | rejects `प्रिया` |
| MAT006 truncation-splits-syllables | all | low | `title.slice(0, n)`, `text[:n]`, `&name[..n]` | `'क्षमा'[:2] == 'क्'`; in Rust a byte cut can panic |
| MAT007 per-character-reversal | all | low | `s[::-1]`, `.split('').reverse()` | `'हिंदी'[::-1]` starts with an orphan vowel sign |

Rust's `\w` already includes marks, so MAT001 skips Rust.

## Fuzz your own functions

Static rules can only guess. The fuzz checks run your function on real words and report exactly which word broke:

```python
from matra.fuzz import check_truncate, check_tokenize, check_validator

check_truncate(my_truncate)     # my_truncate(text, n) -> str: must end on a grapheme boundary
check_tokenize(my_tokenize)     # my_tokenize(text) -> list[str]: must keep words whole
check_validator(is_valid_name)  # is_valid_name(name) -> bool: must accept real names
```

Grapheme boundaries come from Unicode's own rules (UAX #29, including the conjunct rules added in Unicode 15.1), via the `regex` module.

## In CI

```yaml
- uses: RaktimChandra/matra-lint@main
  with:
    min-confidence: medium   # findings also appear in the Security tab
```

## Found in the wild

- A hotel-booking app's `validate_name` used `^[A-Za-z]+...$`. `matra fuzz --kind validate` showed it rejected all 9 real names in 9 scripts (राकेश, முருகன், সৌরভ, ...).
- [Clipy #982](https://github.com/clipy-recorder/clipy/issues/982): a transcript grouper used `char::is_alphanumeric`, which counts vowel signs as letters, so a lone `ि` token after a pause split `कि` into two segments.

## Limits

This is a line-based scanner, not a type checker. It cannot know whether a given `title[:40]` ever sees Indian-script text, which is why truncation and reversal are marked low confidence. Use `--min-confidence medium` for a quieter first run.

## License

MIT
