Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,27 @@ class ClassName {
}
```

## Configuration

By default the rule applies to all functions. You can optionally provide an `ignoreList` list of regex patterns — any function whose name matches a pattern is exempt from the rule.

```js
rules: {
'observation/no-function-without-logging': [
'error',
{
ignoreList: [
'^handle[A-Z].*', // e.g. handleClick, handleChange
'^on[A-Z].*', // e.g. onChange, onPress
'mySpecificFunction',
],
}
]
}
```

Each entry in `ignoreList` is interpreted as a regular expression and tested against the function name. Functions skipped by other built-in exceptions (constructors, getters/setters, setter-like methods, component declarations) are unaffected by this option.

## No Missing Translations

This ESLint rule ensures that every call to `i18n.t(...)` in the codebase has a corresponding key in all translation files. A translation file is defined as an input file for the npm package `i18n-js` (https://www.npmjs.com/package/i18n-js).
Expand Down
30 changes: 30 additions & 0 deletions dist/rules/__tests__/no-function-without-logging.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 46 additions & 18 deletions dist/rules/no-function-without-logging.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions src/rules/__tests__/no-function-without-logging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,36 @@ ruleTester.run("no-function-without-logging", rule, {
filename: "Component",
code: "const Component = () => { Log.debug('Component') }",
},
{
name: "Ignored function declaration is skipped",
options: [{ ignoreList: ["ignoredFunction"] }],
code: "function ignoredFunction(){}",
},
{
name: "Ignored arrow function in variable declaration is skipped",
options: [{ ignoreList: ["ignoredFunction"] }],
code: "const ignoredFunction = () => { }",
},
{
name: "Ignored class method is skipped",
options: [{ ignoreList: ["ignoredFunction"] }],
code: "class ClassName { ignoredFunction(){ } }",
},
{
name: "Ignored class property arrow function is skipped",
options: [{ ignoreList: ["ignoredFunction"] }],
code: "class ClassName { ignoredFunction = () => { } }",
},
{
name: "Ignored function matched by regex pattern is skipped",
options: [{ ignoreList: ["^handle[A-Z].*"] }],
code: "function handleClick(){}",
},
{
name: "Multiple ignore patterns, one matches",
options: [{ ignoreList: ["^handle[A-Z].*", "^on[A-Z].*"] }],
code: "function onChange(){}",
},
],
invalid: [
{
Expand Down
Loading