An ESLint Shareable Config to extend ESLint’s awesome linting powers to macOS JavaScript for Automation (JXA) code.
You'll need to install ESLint first, e.g.:
$ npm install eslint --save-dev
Next, install eslint-config-jxa
, e.g.:
$ npm install eslint-config-jxa --save-dev
Add the relevant configuration to your extends section.
If you use standard JavaScript file extensions (i.e. .js
) for your JXA source code, all you have to do is to add this to your .eslintrc.json
file`:
{
"extends": [
"jxa"
]
}
If you use the .jxa
file extension, extend in an override instead:
{
"overrides": [
{
"files": ["*.jxa"],
"extends": ["jxa"]
}
]
}
There are additional configs available for some special JXA coding scenarios:
- objc: for JXA source that uses the Objective C bridge.
- library: for JXA files intended to be loaded via
Library()
. - injection: for JXA files intended as JXA Infusion injections.
Note these will only work in conjunction with the basic configuration. Because the additional configurations restrict the scope of, or, in the case of the objc rules, entirely disable some ESLint checks, you should only include them in very specific overrides, e.g. (example taken from the JXA Infusion project):
"overrides": [
{
"files": ["*.jxa"],
"extends": ["jxa"]
},
{
"files": ["Injections/**/*.jxa"],
"extends": [
"jxa/objc",
"jxa/injection"
]
},
{
"files": ["Libraries/**/*.jxa"],
"extends": [
"jxa/objc",
"jxa/library"
]
}
]
This config is shared under the MIT License.