Skip to content
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

Feat(eslint): Introduce ultimate ESLint configuration #37

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 3 additions & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
const eslintConfig = require('./packages/eslint-config-lmc');

module.exports = {
reportUnusedDisableDirectives: true,

ignorePatterns: ['node_modules', '!.*.js'],

extends: ['./packages/eslint-config-base', './packages/eslint-config-base/optional', 'prettier'],

plugins: ['prettier'],
...eslintConfig,
};
14 changes: 13 additions & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
module.exports = require('./packages/prettier-config');
const prettierConfig = require('./packages/prettier-config');

module.exports = {
...prettierConfig,
overrides: [
{
files: '*.js',
options: {
printWidth: 80,
},
},
],
};
14 changes: 12 additions & 2 deletions commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,20 @@ module.exports = {
'scope-enum': [
1,
'always',
['browserslist', 'commitlint', 'conventional-changelog', 'prettier', 'stylelint', 'eslint-config-base'],
[
'browserslist',
'commitlint',
'conventional-changelog',
'prettier',
'stylelint',
'eslint',
],
],

'footer-max-line-length': [0],
},
ignores: [(commit) => commit.includes('[CI-SKIP]'), (commit) => commit.includes('Pull request')],
ignores: [
(commit) => commit.includes('[CI-SKIP]'),
(commit) => commit.includes('Pull request'),
],
};
14 changes: 13 additions & 1 deletion packages/commitlint-config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,19 @@ module.exports = {
'type-enum': [
2,
'always',
['Feat', 'Fix', 'Docs', 'Style', 'Refactor', 'Test', 'Revert', 'Perf', 'Chore', 'Deps', 'BREAKING CHANGES'],
[
'Feat',
'Fix',
'Docs',
'Style',
'Refactor',
'Test',
'Revert',
'Perf',
'Chore',
'Deps',
'BREAKING CHANGES',
],
],
'subject-case': [2, 'always', 'sentence-case'],
},
Expand Down
16 changes: 10 additions & 6 deletions packages/conventional-changelog-lmc-bitbucket/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ function formatIssue(issueUrl, issue) {
}

const parserOpts = {
headerPattern: /^(?:Pull request #[0-9]+: )?(?:([a-zA-Z]*-[0-9_]*)(?: ))* ?([\w ]*)(?:\((.*)\))?: (.*)$/,
headerPattern:
/^(?:Pull request #[0-9]+: )?(?:([a-zA-Z]*-[0-9_]*)(?: ))* ?([\w ]*)(?:\((.*)\))?: (.*)$/,
headerCorrespondence: ['body', 'type', 'scope', 'subject'],
noteKeywords: ['BREAKING CHANGE', 'BREAKING CHANGES'],
revertPattern: /^revert:\s([\s\S]*?)\s*This reverts commit (\w*)\./,
Expand Down Expand Up @@ -83,11 +84,14 @@ const writerOpts = {
const issueUrl = context.packageData.bugs && context.packageData.bugs.url;

if (typeof transformedCommit.subject === 'string') {
transformedCommit.subject = transformedCommit.subject.replace(/#([a-zA-Z0-9-]+)/g, (_, issue) => {
issues.push(issue);

return formatIssue(issueUrl, issue);
});
transformedCommit.subject = transformedCommit.subject.replace(
/#([a-zA-Z0-9-]+)/g,
(_, issue) => {
issues.push(issue);

return formatIssue(issueUrl, issue);
},
);
}

// remove references that already appear in the subject
Expand Down
65 changes: 51 additions & 14 deletions packages/conventional-changelog-lmc-bitbucket/tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ betterThanBefore.setups([
shell.exec('git init --template=./git-templates');

gitDummyCommit('Chore: first commit');
gitDummyCommit(['Feat: amazing new module', 'BREAKING CHANGE: Not backward compatible.']);
gitDummyCommit(['Fix(compile): avoid a bug', 'BREAKING CHANGE: The Change is huge.']);
gitDummyCommit([
'Feat: amazing new module',
'BREAKING CHANGE: Not backward compatible.',
]);
gitDummyCommit([
'Fix(compile): avoid a bug',
'BREAKING CHANGE: The Change is huge.',
]);
gitDummyCommit(['Perf(ngOptions): make it faster', ' closes #1, #2']);
gitDummyCommit('Revert(ngOptions): bad commit');
gitDummyCommit('Fix(*): oops');
Expand All @@ -37,12 +43,27 @@ betterThanBefore.setups([
gitDummyCommit(['Feat(awesome): issue brought up by @bcoe! on Friday']);
},
function () {
gitDummyCommit(['Docs(readme): make it clear', 'BREAKING CHANGE: The Change is huge.']);
gitDummyCommit(['Style(whitespace): make it easier to read', 'BREAKING CHANGE: The Change is huge.']);
gitDummyCommit(['Refactor(code): change a lot of code', 'BREAKING CHANGE: The Change is huge.']);
gitDummyCommit(['Test(*): more tests', 'BREAKING CHANGE: The Change is huge.']);
gitDummyCommit([
'Docs(readme): make it clear',
'BREAKING CHANGE: The Change is huge.',
]);
gitDummyCommit([
'Style(whitespace): make it easier to read',
'BREAKING CHANGE: The Change is huge.',
]);
gitDummyCommit([
'Refactor(code): change a lot of code',
'BREAKING CHANGE: The Change is huge.',
]);
gitDummyCommit([
'Test(*): more tests',
'BREAKING CHANGE: The Change is huge.',
]);
gitDummyCommit(['WIP: Just in the middle of something...']);
gitDummyCommit(['Chore(deps): bump', 'BREAKING CHANGE: The Change is huge.']);
gitDummyCommit([
'Chore(deps): bump',
'BREAKING CHANGE: The Change is huge.',
]);
},
function () {
gitDummyCommit(['Feat(deps): bump', 'BREAKING CHANGE Also works :)']);
Expand All @@ -55,8 +76,14 @@ betterThanBefore.setups([
gitDummyCommit(['Feat(foo): add thing', 'closes #1223 #OBG-23']);
},
function () {
gitDummyCommit(['Revert \\"Feat: bad feature\\"', 'This reverts commit 12345.'], false);
gitDummyCommit(['Revert: Feat: custom revert format', 'This reverts commit 5678.']);
gitDummyCommit(
['Revert \\"Feat: bad feature\\"', 'This reverts commit 12345.'],
false,
);
gitDummyCommit([
'Revert: Feat: custom revert format',
'This reverts commit 5678.',
]);
},
function () {
gitDummyCommit([
Expand Down Expand Up @@ -89,7 +116,9 @@ describe('lmc bitbucket preset', () => {
expect(stringifiedChunk).toInclude('make it faster');
expect(stringifiedChunk).toInclude(', closes #1, #2'); // Links are not created
expect(stringifiedChunk).toInclude('Not backward compatible.');
expect(stringifiedChunk).toInclude('**compile:** The Change is huge.');
expect(stringifiedChunk).toInclude(
'**compile:** The Change is huge.',
);
expect(stringifiedChunk).toInclude('Features');
expect(stringifiedChunk).toInclude('Bug Fixes');
expect(stringifiedChunk).toInclude('Performance Improvements');
Expand Down Expand Up @@ -130,7 +159,9 @@ describe('lmc bitbucket preset', () => {
.pipe(
through((chunk) => {
stringifiedChunk = chunk.toString();
expect(stringifiedChunk).toInclude('in [#133](https://jira.int.lmc.cz/browse/133)');
expect(stringifiedChunk).toInclude(
'in [#133](https://jira.int.lmc.cz/browse/133)',
);
done();
}),
);
Expand Down Expand Up @@ -195,7 +226,9 @@ describe('lmc bitbucket preset', () => {
.pipe(
through((chunk) => {
stringifiedChunk = chunk.toString();
expect(stringifiedChunk).toInclude('issue brought up by @bcoe! on Friday');
expect(stringifiedChunk).toInclude(
'issue brought up by @bcoe! on Friday',
);
done();
}),
);
Expand Down Expand Up @@ -332,8 +365,12 @@ describe('lmc bitbucket preset', () => {
(chunk, enc, cb) => {
stringifiedChunk = chunk.toString();

expect(stringifiedChunk).toInclude('https://bitbucket.example.com/projects/EX/repos/example-repo/compare/');
expect(stringifiedChunk).toInclude('https://bitbucket.example.com/projects/EX/repos/example-repo/commits/');
expect(stringifiedChunk).toInclude(
'https://bitbucket.example.com/projects/EX/repos/example-repo/compare/',
);
expect(stringifiedChunk).toInclude(
'https://bitbucket.example.com/projects/EX/repos/example-repo/commits/',
);
expect(stringifiedChunk).toMatch(/some more features \(.*\)/);

i++;
Expand Down
11 changes: 9 additions & 2 deletions packages/eslint-config-base/rules/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@ module.exports = {
// This rule requires or disallows blank lines between the given 2 kinds of statements. Properly
// blank lines help developers to understand the code.
// https://eslint.org/docs/rules/padding-line-between-statements
'padding-line-between-statements': ['error', { blankLine: 'always', prev: '*', next: 'return' }],
'padding-line-between-statements': [
'error',
{ blankLine: 'always', prev: '*', next: 'return' },
],

// Require an empty line between class members
// This rule improves readability by enforcing lines between class members. It will not check
// empty lines before the first member and after the last member, since that is already taken
// care of by padded-blocks.
// https://eslint.org/docs/rules/lines-between-class-members
'lines-between-class-members': ['error', 'always', { exceptAfterSingleLine: true }],
'lines-between-class-members': [
'error',
'always',
{ exceptAfterSingleLine: true },
],

// Enforce Quote Style
// This rule is aimed at ensuring consistency of string quotes.
Expand Down
26 changes: 26 additions & 0 deletions packages/eslint-config-lmc/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const { prettierConfig } = require('@lmc-eu/prettier-config');

module.exports = {
parserOptions: {
ecmaVersion: 'latest',
},

ignorePatterns: ['node_modules', '!.*.js'],

extends: [
'@lmc-eu/eslint-config-base',
'@lmc-eu/eslint-config-base/optional',
'prettier',
],

plugins: ['html', 'markdown', 'prettier'],

rules: {
'prettier/prettier': [
'error',
{
...prettierConfig,
},
],
},
};
18 changes: 18 additions & 0 deletions packages/eslint-config-lmc/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# .eslintignore

node_modules

# NOTE:
# The following directives are only relevant when linting the whole
# project directory, ie. running `eslint .` ⚠️

# If you compile JavaScript into some output folder, exclude it here
dist
**/built

# Highly recommended to re-include JavaScript dotfiles to lint them
# (This will cause .eslintrc.js to be linted by ESLint 🤘)
!.*.js

# Some tools use this pattern for their configuration files. Lint them!
!*.config.js