taichi / vscode-textlint

https://marketplace.visualstudio.com/items?itemName=taichi.vscode-textlint
MIT License
60 stars 19 forks source link

TypeError [ERR_INVALID_ARG_TYPE] #17

Closed swarnendubiswas closed 4 years ago

swarnendubiswas commented 4 years ago

I get the following error when I open (say) .md files in VS Code. The VS Code version is 1.47.+ and the extension version is 0.8.0. OS is Ubuntu 20.04 and node version is 14.5.0.

[Error - 3:57:04 pm] The "listener" argument must be of type Function. Received type object
TypeError [ERR_INVALID_ARG_TYPE]: The "listener" argument must be of type Function. Received type object
    at checkListener (events.js:63:11)
    at _addListener (events.js:219:3)
    at EventEmitter.addListener (events.js:277:10)
    at RuleTypeEmitter.PromiseEventEmitter.on (/home/swarnendu/tmp/textlint-workspace/node_modules/@textlint/kernel/lib/task/promise-event-emitter.js:17:28)
    at /home/swarnendu/tmp/textlint-workspace/node_modules/@textlint/kernel/lib/task/textlint-core-task.js:212:35
    at Array.forEach (<anonymous>)
    at TextLintCoreTask.tryToAddListenRule (/home/swarnendu/tmp/textlint-workspace/node_modules/@textlint/kernel/lib/task/textlint-core-task.js:211:15)
    at /home/swarnendu/tmp/textlint-workspace/node_modules/@textlint/kernel/lib/task/linter-task.js:58:19
    at Array.forEach (<anonymous>)
    at TextLintCoreTask._setupRules (/home/swarnendu/tmp/textlint-workspace/node_modules/@textlint/kernel/lib/task/linter-task.js:49:50)
taichi commented 4 years ago

thanks for your report. which version of textlint do you use?

swarnendubiswas commented 4 years ago

v11.7.6

taichi commented 4 years ago

can I see your configuration file ? and please try below command

node_modules/.bin/textlint *.md

swarnendubiswas commented 4 years ago

This is from my settings.json.

"textlint.nodePath": "/home/swarnendu/tmp/textlint-workspace/node_modules/",
"textlint.configPath": "/home/swarnendu/github/dotfiles/textlintrc.json"
./textlint -c /home/swarnendu/github/dotfiles/textlintrc.json /home/swarnendu/github/dotemacs/README.md 
✖ Error
The "listener" argument must be of type function. Received an instance of Object

✖ Stack trace
TypeError [ERR_INVALID_ARG_TYPE]: The "listener" argument must be of type function. Received an instance of Object
    at checkListener (events.js:110:11)
    at _addListener (events.js:347:3)
    at EventEmitter.addListener (events.js:405:10)
    at RuleTypeEmitter.PromiseEventEmitter.on (/home/swarnendu/tmp/textlint-workspace/node_modules/@textlint/kernel/lib/task/promise-event-emitter.js:17:28)
    at /home/swarnendu/tmp/textlint-workspace/node_modules/@textlint/kernel/lib/task/textlint-core-task.js:212:35
    at Array.forEach (<anonymous>)
    at TextLintCoreTask.tryToAddListenRule (/home/swarnendu/tmp/textlint-workspace/node_modules/@textlint/kernel/lib/task/textlint-core-task.js:211:15)
    at /home/swarnendu/tmp/textlint-workspace/node_modules/@textlint/kernel/lib/task/linter-task.js:58:19
    at Array.forEach (<anonymous>)
    at TextLintCoreTask._setupRules (/home/swarnendu/tmp/textlint-workspace/node_modules/@textlint/kernel/lib/task/linter-task.js:49:50)
taichi commented 4 years ago

thanks. can I see your /home/swarnendu/github/dotfiles/textlintrc.json ?

swarnendubiswas commented 4 years ago

Sure, thanks for looking into the problem.

{
  "filters": {},
  "plugins": [
    "html",
    "latex",
    "latex2e"
  ],
  "rules": {
    "no-todo": true,
    "max-number-of-lines": true,
    "max-comma": true,
    "no-empty-section": true,
    "period-in-list-item": true,
    "alex": true,
    "common-misspellings": true,
    "write-good": true,
    "ginger": true,
    "apostrophe": true,
    "stop-words": true,
    "diacritics": true,
    "sentence-length": true,
    // "no-unmatched-pair": true,
    // "@textlint-rule/no-invalid-control-character": true,
    // "@textlint-rule/no-unmatched-pair": true,
    // "@textlint-rule/proselint": true,
    // "languagetool": true,
    "en-capitalization": true
  }
}

On a different note, I have not been able to get the commented rules to work.

taichi commented 4 years ago

I have try to improve your config file. try this.

{
  "filters": {},
  "plugins": [
    "html",
    "latex",
    "latex2e"
  ],
  "rules": {
    "no-todo": true,
    "max-number-of-lines": true,
    "max-comma": true,
    "no-empty-section": true,
    "period-in-list-item": true,
    "alex": true,
    "common-misspellings": true,
    "write-good": true,
    "ginger": true,
    "apostrophe": true,
    "stop-words": true,
    "diacritics": true,
    "sentence-length": true,
    "@textlint-rule/no-unmatched-pair": true,
    "@textlint-rule/no-invalid-control-character": true,
    "@textlint-rule/proselint": true,
    // "languagetool": true,
    "en-capitalization": true
  }
}

and my package.json

{
  "name": "test",
  "version": "0.0.1",
  "description": "",
  "private": true,
  "dependencies": {
    "@textlint-rule/textlint-rule-no-invalid-control-character": "^1.2.0",
    "@textlint-rule/textlint-rule-no-unmatched-pair": "^1.0.7",
    "@textlint-rule/textlint-rule-proselint": "^1.0.1",
    "textlint-plugin-latex": "^1.0.4",
    "textlint-rule-alex": "^2.1.0",
    "textlint-rule-apostrophe": "^2.0.0",
    "textlint-rule-diacritics": "^1.0.0",
    "textlint-rule-en-capitalization": "^2.0.2",
    "textlint-rule-ginger": "^2.2.1",
    "textlint-rule-max-comma": "^1.0.4",
    "textlint-rule-max-number-of-lines": "^1.0.3",
    "textlint-rule-no-empty-section": "^1.1.0",
    "textlint-rule-period-in-list-item": "^0.3.2",
    "textlint-rule-stop-words": "^2.0.6",
    "textlint-rule-write-good": "^1.6.2"
  },
  "devDependencies": {
    "textlint": "^11.7.6",
    "textlint-plugin-html": "^0.2.0",
    "textlint-plugin-latex2e": "^1.0.0",
    "textlint-rule-common-misspellings": "^1.0.1",
    "textlint-rule-no-todo": "^2.0.1",
    "textlint-rule-preset-ja-technical-writing": "^4.0.1"
  },
  "scripts": {
    "fix": "textlint --fix testtest.txt",
    "lint": "textlint testtest.txt"
  },
  "author": "taichi",
  "license": "MIT"
}
taichi commented 4 years ago

languagetool depends on node-jre. and node-jre have been deprecated. see. https://www.npmjs.com/package/node-jre so I don't recommed you to use languagetool .

swarnendubiswas commented 4 years ago

Thanks for the suggestion. My package.json looks different from you. How do I integrate your changes, for example, dependencies?

This is what I did to setup textlint.

cd $HOME/tmp; mkdir textlint-workspace; cd ;
npm init --yes
npm install --save-dev textlint textlint-rule-no-todo textlint-rule-no-start-duplicated-conjunction textlint-rule-max-number-of-lines textlint-rule-max-comma textlint-rule-no-empty-section textlint-rule-terminology textlint-rule-period-in-list-item textlint-rule-ginger  textlint-rule-en-capitalization textlint-rule-no-surrogate-pair textlint-rule-spelling textlint-rule-common-misspellings textlint-rule-write-good textlint-rule-apostrophe textlint-rule-diacritics textlint-rule-stop-words textlint-plugin-json textlint-plugin-html textlint-rule-sentence-length textlint-plugin-latex textlint-plugin-latex2e textlint-rule/textlint-rule-no-invalid-control-character textlint-rule/textlint-rule-no-unmatched-pair textlint-rule/textlint-rule-proselint
swarnendubiswas commented 4 years ago

My package.json.

{
  "name": "textlint-workspace",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@textlint-rule/textlint-rule-no-invalid-control-character": "github:textlint-rule/textlint-rule-no-invalid-control-character",
    "@textlint-rule/textlint-rule-no-unmatched-pair": "github:textlint-rule/textlint-rule-no-unmatched-pair",
    "@textlint-rule/textlint-rule-proselint": "github:textlint-rule/textlint-rule-proselint",
    "textlint": "^11.7.6",
    "textlint-plugin-html": "^0.2.0",
    "textlint-plugin-json": "0.0.1",
    "textlint-plugin-latex": "^1.0.4",
    "textlint-rule-apostrophe": "^2.0.0",
    "textlint-rule-common-misspellings": "^1.0.1",
    "textlint-rule-diacritics": "^1.0.0",
    "textlint-rule-max-comma": "^1.0.4",
    "textlint-rule-max-number-of-lines": "^1.0.3",
    "textlint-rule-no-empty-section": "^1.1.0",
    "textlint-rule-no-start-duplicated-conjunction": "^2.0.2",
    "textlint-rule-no-surrogate-pair": "^1.0.1",
    "textlint-rule-no-todo": "^2.0.1",
    "textlint-rule-period-in-list-item": "^0.3.2",
    "textlint-rule-sentence-length": "^2.2.0",
    "textlint-rule-spelling": "^0.2.0",
    "textlint-rule-stop-words": "^2.0.6",
    "textlint-rule-terminology": "^2.1.4",
    "textlint-rule-write-good": "^1.6.2"
  },
  "dependencies": {
    "@textlint-rule/textlint-rule-no-invalid-control-character": "^1.2.0",
    "@textlint-rule/textlint-rule-no-unmatched-pair": "^1.0.7",
    "@textlint-rule/textlint-rule-proselint": "^1.0.1",
    "textlint-plugin-latex": "^1.0.4",
    "textlint-rule-alex": "^2.1.0",
    "textlint-rule-apostrophe": "^2.0.0",
    "textlint-rule-diacritics": "^1.0.0",
    "textlint-rule-en-capitalization": "^2.0.2",
    "textlint-rule-ginger": "^2.2.1",
    "textlint-rule-max-comma": "^1.0.4",
    "textlint-rule-max-number-of-lines": "^1.0.3",
    "textlint-rule-no-empty-section": "^1.1.0",
    "textlint-rule-period-in-list-item": "^0.3.2",
    "textlint-rule-stop-words": "^2.0.6",
    "textlint-rule-write-good": "^1.6.2"
  }
}
taichi commented 4 years ago

ok. I improve your package.json

{
  "name": "textlint-workspace",
  "version": "1.0.0",
  "description": "",
  "keywords": [],
  "license": "ISC",
  "author": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "dependencies": {
    "@textlint-rule/textlint-rule-no-invalid-control-character": "^1.2.0",
    "@textlint-rule/textlint-rule-no-unmatched-pair": "^1.0.7",
    "@textlint-rule/textlint-rule-proselint": "^1.0.1",
    "textlint": "^11.7.6",
    "textlint-plugin-html": "^0.2.0",
    "textlint-plugin-json": "0.0.1",
    "textlint-plugin-latex": "^1.0.4",
    "textlint-plugin-latex2e": "^1.0.0",
    "textlint-rule-alex": "^2.1.0",
    "textlint-rule-apostrophe": "^2.0.0",
    "textlint-rule-common-misspellings": "^1.0.1",
    "textlint-rule-diacritics": "^1.0.0",
    "textlint-rule-en-capitalization": "^2.0.2",
    "textlint-rule-ginger": "^2.2.1",
    "textlint-rule-max-comma": "^1.0.4",
    "textlint-rule-max-number-of-lines": "^1.0.3",
    "textlint-rule-no-empty-section": "^1.1.0",
    "textlint-rule-no-start-duplicated-conjunction": "^2.0.2",
    "textlint-rule-no-surrogate-pair": "^1.0.1",
    "textlint-rule-no-todo": "^2.0.1",
    "textlint-rule-period-in-list-item": "^0.3.2",
    "textlint-rule-sentence-length": "^2.2.0",
    "textlint-rule-spelling": "^0.2.0",
    "textlint-rule-stop-words": "^2.0.6",
    "textlint-rule-terminology": "^2.1.4",
    "textlint-rule-write-good": "^1.6.2"
  }
}

run npm install inside your project root.

swarnendubiswas commented 4 years ago

This is the log from VS Code Insiers.

events.js:180
      throw er; // Unhandled 'error' event
      ^

Error: spawn /usr/share/code-insiders/code-insiders ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:264:19)
    at onErrorNT (internal/child_process.js:456:16)
    at processTicksAndRejections (internal/process/task_queues.js:77:11)
Emitted 'error' event at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:270:12)
    at onErrorNT (internal/child_process.js:456:16)
    at processTicksAndRejections (internal/process/task_queues.js:77:11) {
  errno: 'ENOENT',
  code: 'ENOENT',
  syscall: 'spawn /usr/share/code-insiders/code-insiders',
  path: '/usr/share/code-insiders/code-insiders',
  spawnargs: [
    '-e',
    "var p = process;p.on('message',function(m){if(m.c==='e'){p.exit(0);}else if(m.c==='rs'){try{var r=require.resolve(m.a);p.send({c:'r',s:true,r:r});}catch(err){p.send({c:'r',s:false});}}});",
    ''
  ]
}
[Info  - 6:34:19 am] Connection to server got closed. Server will restart.
swarnendubiswas commented 4 years ago

I set up textlint with package.json from https://github.com/taichi/vscode-textlint/issues/17#issuecomment-668583669, and now the extension works as expected. Thanks.

It seems the error was in how I set up textlint.