New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
body-max-line-length
should not report false positives for line starts with #
#2964
Comments
It might be related to https://github.com/conventional-changelog/commitlint/blob/master/%40commitlint/cli/src/cli.ts#L227 As I'm not using |
Thanks for reporting. Are you interested in creating a PR for this? |
When calling through const load = require('@commitlint/load').default
const lint = require('@commitlint/lint').default;
const config = {
parserPreset: {
parserOpts: {
commentChar: '#', // <----
},
},
rules: {
'body-max-line-length': [2, 'always', 20]
},
};
const opts = {
parserOpts: config.parserPreset.parserOpts,
plugins: {},
ignores: [],
defaultIgnores: true,
};
(async () => {
const loaded = await load(config);
const out = await lint(`feat: hello
# this is a very long line that exceeds the body-max-line-length rule, but has a comment character in the beginning so should be ignored
`, loaded.rules, opts);
console.log(out.valid); // true
})(); Change the Are you in a situation where that's difficult to pass in? |
Oh, thanks for you support here @Zirak ! |
Thanks for the description, I passed in Then in the module.exports = {
extends: ['@commitlint/config-conventional'],
parserPreset: require.resolve('@xxx/conventional-changelog'),
} But To be brief, several format of exports are valid:
Unfortunately, Then I have to manually handle 2-4 logic. Would be appreciated if all edge case could be handled and the type should not be just unknown. export interface ParserPreset {
name?: string;
path?: string;
parserOpts?: unknown;
} |
Ah I see, so it's a broken expectation between how a rule is resolved and how It seems like Correct me if I'm wrong here @escapedcat (or someone else), it seems like this is a feature, and 3 and 4 could be supported by changing this condition: commitlint/@commitlint/load/src/utils/load-parser-opts.ts Lines 44 to 49 in bcb95b0
...to not only check for functions whose name begins with |
Actually my bad, I read that piece of code completely wrong. We won't even reach that part because of an earlier check up in the function: commitlint/@commitlint/load/src/utils/load-parser-opts.ts Lines 20 to 22 in bcb95b0
So inside this block (or elsewhere if it fits the flow), something like the following: if (typeof parser === 'function') {
return loadParserOpts(parser());
} |
I just wonder why these two lines exists? // Create parser opts from factory
if (isParserOptsFunction(parser) &&
typeof parser.name === 'string' && // why this line ?
parser.name.startsWith('conventional-changelog-')) { // why this line ? Why the following codes are not OK? // Create parser opts from factory
if (isParserOptsFunction(parser)) { |
@armano2 you have an idea or input to this? Sorry for bothering! |
From my understanding @xboy2012, that logic isn't reached. Since earlier in the function there's a check which filters out all non-objects, no matter what function is passed in the result is loadParserOpts(() => {}) // undefined It applies to passing in an object with a loadParserOpts({
name: 'conventional-changelog-example',
parserOpts: () => {}, // <-- this will be called
}) As I mentioned above, function support could be added by conditionally checking for passing in functions earlier in the code, and dealing with that there. If there's interest I can draw up a PR. |
Previously, `load` could accept `parserPresets` as both values and promises of values. Per conventional-changelog#2964 however, there was expectations for it to also support functions returning said values. This commit enables to specify `parserPresets` in all the same ways as rules. That is, both commitlint rules and `parserPresets` can be specified as: - Plain values - Promises - Functions returning plain values - Functions returning promises Solves conventional-changelog#2964.
Previously, `load` could accept `parserPresets` as both values and promises of values. Per conventional-changelog#2964 however, there was expectations for it to also support functions returning said values. This commit enables to specify `parserPresets` in all the same ways as rules. That is, both commitlint rules and `parserPresets` can be specified as: - Plain values - Promises - Functions returning plain values - Functions returning promises Solves conventional-changelog#2964.
Previously, `load` could accept `parserPresets` as both values and promises of values. Per #2964 however, there was expectations for it to also support functions returning said values. This commit enables to specify `parserPresets` in all the same ways as rules. That is, both commitlint rules and `parserPresets` can be specified as: - Plain values - Promises - Functions returning plain values - Functions returning promises Solves #2964.
Closing this because of no negative feedback so far |
Expected Behavior
body-max-line-length
should not report false positives for line starts with#
Current Behavior
body-max-line-length
report false positives for line starts with#
While debuging in the
node_modules/@commitlint/rules/lib/body-max-line-length.js
I found
parsed.body
have the following value as follows:Obviously, the lines come from the
git commit
command line, and should be ignored as they starts with#
Affected packages
Possible Solution
Steps to Reproduce (for bugs)
commitlint.config.js
```js ```Context
Your Environment
commitlint --version
git --version
node --version
The text was updated successfully, but these errors were encountered: