πPutout operator adds ability to declare referenced variables that was not defined
npm install @putout/operator-declare[NPMIMGURL]: https://img.shields.io/npm/v/@putout/operator-declare.svg?style=flat&longCache=true
[NPMURL]: https://npmjs.org/package/@putout/operator-declare "npm"
πPutout operator adds ability to declare variables that has references with no definitions. Most likely you prefer using Declarator plugin type based on current Operator.
```
npm i putout @putout/operator-declare
If you want to create πPutout plugin that will declare variables according to your needs just:
`js
import {operator} from 'putout';
const {declare} = operator;
export const {
report,
include,
fix,
filter,
} = declare({
fs: import fs from 'fs/promises',`
});
When you need different declarations for ESM and CommonJS you can use:
`js
const {operator} = require('putout');
const {declare} = operator;
export const {
report,
include,
fix,
filter,
} = declare({
fs: {
esm: import fs from 'fs/promises',const fs = require('fs')
comomnjs: , // drop when not needed`
},
});
Plugin supports options, so you can pass it in .putout.json:
`json`
{
"rules": {
"putout/declare": ["on", {
"declarations": {
"fs": "import fs from 'fs/promises'"
}
}]
}
}
If for some reason you don't need some kind of declaration, add dismiss field and it will be ignored:
`json`
{
"rules": {
"putout/declare": ["on", {
"declarations": {
"fs": "import fs from 'fs/promises'"
},
"dismiss": ["fs"]
}]
}
}
If you want to override type to avoid detecting, set it to esm|commonjs:
`json`
{
"rules": {
"putout/declare": ["on", {
"declarations": {
"fs": "import fs from 'fs/promises'"
},
"dismiss": ["fs"],
"type": "esm"
}]
}
}
- β
declare
- β
tape/declare
- β
putout/declare
- β
nodejs/declare
- β
react-hooks/declare
- β
try-catch/declare
- β
montag/declare
- β
madrun/declare
- β
maybe/declare
Can be used with ESLint's putout/evaluate:
`json./
{
"rules": {
"putout/declare": ["on", {
"declarations": {
"superMethod": "import superMethod from '__putout_evaluate: join(, basename(__filename), .js)'"`
}
}]
}
}
If you have a file index.spec.js:
`diff``
+ import superMethod from './index.js'
superMethod();
MIT