Skip to content

Commit

Permalink
Replace deprecated padding-line-between-statements with `@stylistic…
Browse files Browse the repository at this point in the history
…/js/padding-line-between-statements` (#278)
  • Loading branch information
ybiquitous committed Jun 24, 2024
1 parent 6079dd1 commit c7acf9d
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Head

- Changed: replace deprecated `padding-line-between-statements` with `@stylistic/js/padding-line-between-statements`.
- Fixed: missing `funding` field in `package.json`.

## 21.0.0
Expand Down
46 changes: 44 additions & 2 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const { ESLint } = require('eslint');
const config = require('../index');
const { isObject } = require('./helper');

const newESLint = () => new ESLint({ baseConfig: config, useEslintrc: false, fix: true });

test('basic properties of config', () => {
assert(isObject(config.parserOptions));
assert(isObject(config.env));
Expand All @@ -17,8 +19,48 @@ test('basic properties of config', () => {
});

test('load config in ESLint to validate all rule syntax is correct', async () => {
const eslint = new ESLint({ baseConfig: config, useEslintrc: false });
const results = await eslint.lintText('var foo\n');
const results = await newESLint().lintText('var foo\n');

assert(results);
});

test('padding-line-between-statements', async () => {
const code = `
const asdf = 'dfsdf';
function xxcv() {
const sdfsdf = 'sdfsdf';
return sdfsdf;
}
for (let i = 0; i < 10; i++) {
console.log(i);
}
const asdfsfd = 'sdfsdf';
if (true) {
console.log('true');
}
`;

const results = await newESLint().lintText(code);

const expected = `
const asdf = 'dfsdf';
function xxcv() {
const sdfsdf = 'sdfsdf';
return sdfsdf;
}
for (let i = 0; i < 10; i++) {
console.log(i);
}
const asdfsfd = 'sdfsdf';
if (true) {
console.log('true');
}
`;

assert.equal(results[0].output, expected);
});
19 changes: 11 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = {
'plugin:regexp/recommended',
'prettier',
],
plugins: ['@stylistic/js'],
rules: {
'array-callback-return': 'error',
'dot-notation': 'error',
Expand Down Expand Up @@ -57,7 +58,16 @@ module.exports = {
'object-shorthand': 'error',
'one-var': ['error', 'never'],
'operator-assignment': 'error',
'padding-line-between-statements': [
'prefer-arrow-callback': 'error',
'prefer-object-spread': 'error',
'prefer-regex-literals': 'error',
'prefer-rest-params': 'error',
'prefer-spread': 'error',
'prefer-template': 'error',
'sort-imports': ['error', { allowSeparatedGroups: true }],

// Migrated from the deprecated built-in 'padding-line-between-statements'
'@stylistic/js/padding-line-between-statements': [
'error',
// Require blank lines after all directive prologues (e. g. 'use strict')
{
Expand Down Expand Up @@ -101,13 +111,6 @@ module.exports = {
next: '*',
},
],
'prefer-arrow-callback': 'error',
'prefer-object-spread': 'error',
'prefer-regex-literals': 'error',
'prefer-rest-params': 'error',
'prefer-spread': 'error',
'prefer-template': 'error',
'sort-imports': ['error', { allowSeparatedGroups: true }],

// Avoid a global variable unique to Node.js.
'n/prefer-global/process': ['error', 'never'],
Expand Down
74 changes: 69 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
},
"prettier": "@stylelint/prettier-config",
"dependencies": {
"@stylistic/eslint-plugin-js": "^2.2.2",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-n": "^17.7.0",
"eslint-plugin-regexp": "^2.6.0"
Expand Down

0 comments on commit c7acf9d

Please sign in to comment.