textlint-rule / textlint-rule-preset-google

[WIP] Google Developer Documentation Style Guide for textlint.
https://developers.google.com/style/
MIT License
14 stars 3 forks source link

capitalization rule doesn't work with textlint 11 #35

Closed KengoTODA closed 6 years ago

KengoTODA commented 6 years ago

I met following error when I run latest textlint-rule-preset-google@0.1.0 with textlint@11.0.0:

✖ Error
Error while loading rule '@textlint-rule/preset-google/capitalization': Cannot assign to read only property 'report' of object '#<RuleContext>'

✖ Stack trace
TypeError: Error while loading rule '@textlint-rule/preset-google/capitalization': Cannot assign to read only property 'report' of object '#<RuleContext>'
    at Function.assign (<anonymous>)
    at /home/kengo/GitHub/spotbugs/docs/node_modules/@textlint-rule/textlint-rule-google-capitalization/lib/textlint-rule-google-capitalization.js:15:44
    at TextLintCoreTask.tryToGetRuleObject (/home/kengo/GitHub/spotbugs/docs/node_modules/@textlint/kernel/lib/kernel/src/task/textlint-core-task.js:152:20)
    at TextLintCoreTask.tryToAddListenRule (/home/kengo/GitHub/spotbugs/docs/node_modules/@textlint/kernel/lib/kernel/src/task/textlint-core-task.js:181:20)
    at /home/kengo/GitHub/spotbugs/docs/node_modules/@textlint/kernel/lib/kernel/src/task/linter-task.js:53:19
    at Array.forEach (<anonymous>)
    at TextLintCoreTask._setupRules (/home/kengo/GitHub/spotbugs/docs/node_modules/@textlint/kernel/lib/kernel/src/task/linter-task.js:44:50)
    at new TextLintCoreTask (/home/kengo/GitHub/spotbugs/docs/node_modules/@textlint/kernel/lib/kernel/src/task/linter-task.js:28:15)
    at LinterProcessor.process (/home/kengo/GitHub/spotbugs/docs/node_modules/@textlint/kernel/lib/kernel/src/linter/linter-processor.js:24:20)
    at TextlintKernel._parallelProcess (/home/kengo/GitHub/spotbugs/docs/node_modules/@textlint/kernel/lib/kernel/src/textlint-kernel.js:130:14)
    at /home/kengo/GitHub/spotbugs/docs/node_modules/@textlint/kernel/lib/kernel/src/textlint-kernel.js:74:26
    at <anonymous>
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ lint: `textlint a*.rst`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @ lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

This is caused by Object.assign in the following code. https://github.com/textlint-rule/textlint-rule-preset-google/blob/v0.1.0/packages/textlint-rule-google-capitalization/src/textlint-rule-google-capitalization.js#L13-L19

Maybe this plugin needs to follow the breaking change in textlint 11, but I cannot find related change in the release note.

azu commented 6 years ago

I've confirmed it.

This error is caused by frozen context object. It is introduced in textlint 11

// Throw Error because `context` is read-only object
context.report = () => {}

This change aim to prevent that hacky way :-)

azu commented 6 years ago

I've fixed it and released https://github.com/textlint-rule/textlint-rule-preset-google/releases/tag/v0.1.2

KengoTODA commented 6 years ago

Thanks, it worked! https://github.com/spotbugs/spotbugs/commit/53b7f79fe0ca23e94e8a039a7d619545ce000288