# @modix/smarty-lint

> Find and fix problems in your Smarty 3 code

Latest version **0.3.3** (published 2019-12-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install @modix/smarty-lint
pnpm add @modix/smarty-lint
yarn add @modix/smarty-lint
bun add @modix/smarty-lint
```

Provides the command `smarty-lint`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.3 |
| Published | 2019-12-19 |
| First published | 2019-12-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 305.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Modix GmbH |
| Maintainers | jens-duttke, meatgear, modix-user, mx-hq-product |

## Links

- npm: https://www.npmjs.com/package/@modix/smarty-lint
- Repository: https://github.com/Modix/smarty-lint
- Homepage: https://github.com/Modix/smarty-lint#readme
- Issues: https://github.com/Modix/smarty-lint/issues
- npm.io page: https://npm.io/package/@modix/smarty-lint

## Dependencies (3)

- [glob](https://npm.io/package/glob.md) ^7.1.6
- [vscode-textmate](https://npm.io/package/vscode-textmate.md) ^4.4.0
- [@modix/smarty-tmlanguage](https://npm.io/package/@modix/smarty-tmlanguage.md) ^1.1.0

## Recent versions

- 0.3.3 (latest) — 2019-12-19
- 0.3.2 — 2019-12-19
- 0.3.1 — 2019-12-19
- 0.3.0 — 2019-12-19
- 0.2.0 — 2019-12-19
- 0.1.5 — 2019-12-19
- 0.1.4 — 2019-12-18
- 0.1.3 — 2019-12-17
- 0.1.2 — 2019-12-17
- 0.1.1 — 2019-12-17
- 0.1.0 — 2019-12-17

## README

# Smarty-Lint

<img src="https://cdn.jsdelivr.net/gh/Modix/smarty-lint/screenshot-vscode.png" width="100%" />

## Installation

```
npm install @modix/smarty-lint --save-dev
```

## Run

package.json:
```json
{
  "scripts": {
    "lint": "smarty-lint"
  }
}
```

## Configuration file

By specifying a `smartylint.json` (or `smartylint.js`) file in the root of your project, you are able to configure which files shall be parsed, and which rules shall be applied.

### Example

```json
{
  "files": [
    "**/*.tpl"
  ],
  "rules": {
    "allowed-function-names": ["error", {
      "allowedFunctions": [
        "assign", "ldelim", "rdelim", "break", "continue",
        "mdx_elem", "mdx_mod"
      ],
      "allowedModifiers": ["tolower", "toupper", "floor", "round", "ceil"],
      "functions": ["mdx_getlocale", "mdx_loopcount"],
      "modifiers": ["explode"]
    }],
    "deprecated-function-names": ["warn", {
      "functions": ["mdx_loopcount", "mdx_getlocale"],
      "modifiers": ["explode"]
    }],
    "empty-block": "warn",
    "empty-comment": "warn",
    "eqeqeq": ["warn", {
      "ignore": ["=="]
      }],
    "lower-case-identifier": ["warn", {
      "ignore": ["namedAttribute", "property", "variable"]
    }],
    "unnecessary-encapsulation": "warn",
    "unquoted-string": ["warn", {
      "ignore": ["array"]
    }]
  }
}
```

## Available built-in rules

## `allowed-function-names`

Allow only specific function and modifier names.

> :warning: This rule is **NOT** applied on block functions (`{if}`, `{elseif}`, `{else}`, `{foreach}`, `{strip}`, `{literal}`, `{function}`, `{section}` etc.), but it's applied on built-in functions like `{assign}`, `{ldelim}`, `{rdelim}`, `{break}`, `{continue}`.

### Options

| Name | Type | Description |
|-|-|-|
| functions | string[] | A list of function names which are allowed. |
| modifiers | string[] | A list of modifier names which are allowed. |

### Example

```
{does_not_exist}
{$a|does_not_exist}
```

## `deprecated-function-names`

Show a deprecation-warning for specific function and modifier names.

### Options

| Name | Type | Description |
|-|-|-|
| functions | string[] | A list of function names which shall produce a deprecation warning. |
| modifiers | string[] | A list of modifier names which shall produce a deprecation warning. |

### Example

```
{mdx_getlocale}
{$a|explode}
```

## `empty-block`

This rule checks if the code contains empty blocks.

### Example

```
{if true}
  ...
{else}
{/if}

{literal}{/literal}
```

## `empty-comment`

This rule checks if the code contains empty Smarty comments.

### Example

```
{* *}
```

## `eqeqeq`

It is considered good practice to use the type-safe equality operators `===` and `!==` instead of their regular counterparts `==` and `!=`.

The reason for this is that `==` and `!=` do type coercion. For instance, the following statements are all considered true:

```
[] == false
3 == "03"
0 == 'K'
```

If one of those occurs in an innocent-looking statement such as `$a == $b` the actual problem is very difficult to spot.

| If you use | it recommends |
|-|-|
| `!=` | `!==` |
| `==` | `===` |
| `and` | `&&` |
| `or` | `||` |
| `eq` | `===` |
| `neq` | `!==` |
| `ne` | `!==` |
| `gte` | `>=` |
| `gt` | `>` |
| `ge` | `>=` |
| `lte` | `<=` |
| `lt` | `<` |
| `le` | `<=` |
| `mod` | `%` |

### Options

| Name | Type | Description |
|-|-|-|
| ignore | string[] | A list of operators which shall be ignored. |

### Example

```
{if $a == $b}
  ...
{/if}
```

## `lower-case-identifier`

Make sure identifiers are written in lower case.

Identifiers are used in arithmetic operators (`mod`), logical operators (`and`, `or`, `eq` etc.), constants (`true`, `false`, `null`) and idenfiers of functions (`mdx_vadump`, `literal`, `foreach` etc.) and modifiers (`strpos`, `regex_replace` etc.)

### Options

| Name | Type | Description |
|-|-|-|
| ignore | string[] | A list of token types which shall be ignored. |

### Example

```
{mdx_varDump "TITLE"|strPos}
```

## `unnecessary-encapsulation`

Checks if the code contains encapsulations which are not required. Unnecessary encapsulation makes the code harder to read.

```
{(1)}
{"Test"}
```

## `unquoted-string`

Unquoted string are the source of errors which are hard to find. That's why it's always recommended to use double-quoted or single-quoted strings.


### Options

| Name | Type | Description |
|-|-|-|
| ignore | string[] | A list of parent token types were unquoted strings are allowed (e.g. "array"), if it should be allowed as array-key. |

### Example

```
{$a = if mod 5}
```

---
_Source: https://npm.io/package/@modix/smarty-lint · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
