Skip to content

Commit

Permalink
feat(upgrade): eslint@8
Browse files Browse the repository at this point in the history
  • Loading branch information
Святослав Зайцев committed Jul 8, 2022
1 parent 4a7f27f commit e00f402
Show file tree
Hide file tree
Showing 10 changed files with 4,185 additions and 3,935 deletions.
7 changes: 7 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"plugins": [
["@babel/plugin-proposal-decorators", {
"version": "2021-12"
}]
]
}
6 changes: 3 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ module.exports = {

// Optional jest rules:
'jest/consistent-test-it': 'error',
'jest/lowercase-name': 'error',
'jest/prefer-lowercase-title': 'error',
'jest/no-duplicate-hooks': 'error',
'jest/no-expect-resolves': 'error',
'jest/prefer-expect-resolves': 'error',
'jest/no-hooks': 'error',
'jest/no-if': 'error',
'jest/no-large-snapshots': 'error',
Expand Down Expand Up @@ -155,7 +155,7 @@ module.exports = {
// Markdown code samples in documentation:
files: ['**/*.md'],
plugins: ['markdown'],
parser: 'babel-eslint',
parser: 'markdown-eslint-parser',
parserOptions: {
sourceType: 'module',
ecmaFeatures: { legacyDecorators: true },
Expand Down
1 change: 1 addition & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ module.exports = {
semi: true,
singleQuote: true,
trailingComma: 'es5',
endOfLine: 'auto',
};
30 changes: 13 additions & 17 deletions lib/rules/decorator-position.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
'use strict';

const { CLIEngine } = require('eslint');
const { CLIEngine } = require('eslint/lib/cli-engine');

const cli = new CLIEngine();

module.exports = {
meta: {
type: 'layout',
fixable: 'code',
docs: {
description: 'Enforces consistent decorator position on properties and methods',
description: 'enforce consistent decorator position on properties and methods',
category: 'Style',
recommended: true,
url: 'https://github.com/NullVoxPopuli/eslint-plugin-decorator-position/tree/master/docs/rules/decorator-position.md',
},

fixable: 'code',
schema: {
definitions: {
decoratorConfig: {
Expand Down Expand Up @@ -79,6 +78,8 @@ module.exports = {
},
],
},

messages: [],
},

create: decoratorPositionRule,
Expand Down Expand Up @@ -142,12 +143,11 @@ function decoratorPositionRule(context) {
const options = normalizeOptions({ ...userOptions, printWidth });

return {
'ClassProperty[decorators.length=1]:exit'(node) {
'ClassDeclaration > ClassBody > PropertyDefinition[decorators.length=1]'(node) {
applyOverrides(context, node, options);
positionDecorator(context, node, options);
},
// NOTE: both getters and methods are of type MethodDefinition
'MethodDefinition[decorators.length=1]:exit'(node) {
}, // NOTE: both getters and methods are of type MethodDefinition
'ClassDeclaration > ClassBody > MethodDefinition[decorators.length=1]:exit'(node) {
applyOverrides(context, node, options);
positionDecorator(context, node, options);
},
Expand Down Expand Up @@ -179,7 +179,7 @@ function positionDecorator(context, node, options) {
const position = options[key];

const isMemberRelevant =
(key === PROPERTIES && node.type === 'ClassProperty') ||
(key === PROPERTIES && node.type === 'PropertyDefinition') ||
(key === METHODS && node.type === 'MethodDefinition');

let overridesConfig;
Expand Down Expand Up @@ -392,8 +392,7 @@ function lengthAsInline(context, node) {
// - type annotation (and !)
// - etc
return (
context.getSourceCode().getText(node).replace(/\s+/, ' ').length +
// this is the only way to get indentation?
context.getSourceCode().getText(node).replace(/\s+/, ' ').length + // this is the only way to get indentation?
node.loc.start.column
);
}
Expand Down Expand Up @@ -426,12 +425,9 @@ function decoratorInfo(context, node, decoratorConfig, options) {

const decoratorName = nameOfDecorator(decorator);
const arity = arityOfDecorator(decorator);
const arityMatches =
// we don't care what the args are, if they exist
decoratorOptions.withArgs === undefined ||
// this config requires args, so ensure the decorator has them
(decoratorOptions.withArgs === true && arity >= 0) ||
// this config requires no args, so ensure the decorator doesn't have them
const arityMatches = // we don't care what the args are, if they exist
decoratorOptions.withArgs === undefined || // this config requires args, so ensure the decorator has them
(decoratorOptions.withArgs === true && arity >= 0) || // this config requires no args, so ensure the decorator doesn't have them
(decoratorOptions.withArgs === false && arity === undefined);

const positioning = linePositioning(decorator, key);
Expand Down
23 changes: 13 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-decorator-position",
"version": "4.0.1",
"version": "5.0.0",
"description": "ESLint plugin for enforcing decorator position",
"main": "lib/index.js",
"files": [
Expand All @@ -13,7 +13,7 @@
"scripts": {
"changelog": "lerna-changelog",
"lint": "npm-run-all lint:* --continue-on-error",
"lint:docs": "markdownlint '**/*.md'",
"lint:docs": "markdownlint **/*.md",
"lint:docs-js": "eslint . --cache --ext md",
"lint:js": "eslint . --cache",
"start": "yarn run test:watch",
Expand Down Expand Up @@ -62,34 +62,37 @@
"@commitlint/config-conventional": "16.0.0",
"@semantic-release/changelog": "6.0.1",
"@semantic-release/git": "10.0.1",
"@typescript-eslint/parser": "4.33.0",
"babel-eslint": "10.1.0",
"@typescript-eslint/parser": "5.30.5",
"common-tags": "1.8.2",
"prettier": "2.5.1",
"eslint": "^7.32.0",
"eslint": "8.19.0",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-eslint-comments": "3.2.0",
"eslint-plugin-eslint-plugin": "3.0.0",
"eslint-plugin-eslint-plugin": "4.4.0",
"eslint-plugin-filenames": "1.3.2",
"eslint-plugin-import": "2.22.1",
"eslint-plugin-jest": "24.7.0",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-jest": "26.5.3",
"eslint-plugin-markdown": "1.0.2",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-prettier": "4.0.0",
"jest": "27.4.7",
"lerna-changelog": "2.2.0",
"markdownlint-cli": "0.30.0",
"npm-run-all": "4.1.5",
"prettier": "2.5.1",
"semantic-release": "19.0.2",
"typescript": "4.5.5"
},
"dependencies": {
"@babel/core": "^7.18.6",
"@babel/eslint-parser": "^7.18.2",
"@babel/plugin-proposal-decorators": "^7.18.6",
"@ember-data/rfc395-data": "^0.0.4",
"ember-rfc176-data": "^0.3.12",
"eslint-plugin-md": "^1.0.19",
"snake-case": "^3.0.3"
},
"peerDependencies": {
"eslint": "^7.31.0"
"eslint": "^8.0.0"
},
"changelog": {
"repo": "NullVoxPopuli/eslint-plugin-decorator-position",
Expand Down
33 changes: 0 additions & 33 deletions tests/helpers/faux-context.js

This file was deleted.

4 changes: 2 additions & 2 deletions tests/lib/rules/decorator-position-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// Requirements
//------------------------------------------------------------------------------

const parser = require.resolve('babel-eslint');
const parser = require.resolve('@babel/eslint-parser');

const { stripIndent } = require('common-tags');
const RuleTester = require('eslint').RuleTester;
const { RuleTester } = require('eslint');

const rule = require('../../../lib/rules/decorator-position');
// const { ERROR_MESSAGE } = rule;
Expand Down
15 changes: 15 additions & 0 deletions tests/lib/rules/decorator-position-ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,20 @@ tsRuleTester.run('TS: decorator-position', rule, {
}
`,
},
{
code: stripIndent`
export default class LocaleSwitcher extends Component<IArgs> {
@service
locale(): LocaleService {}
}
`,
options: [{ overrides: { 'prefer-inline': ['@service'] } }],
errors: [{ message: 'Expected @service to be inline.' }],
output: stripIndent`
export default class LocaleSwitcher extends Component<IArgs> {
@service locale(): LocaleService {}
}
`,
},
],
});
4 changes: 2 additions & 2 deletions tests/plugin-exports.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

const plugin = require('../lib');
const base = require('../lib/config/base.js');
const ember = require('../lib/config/ember.js');
const base = require('../lib/config/base');
const ember = require('../lib/config/ember');

describe('plugin exports', () => {
describe('configs', () => {
Expand Down
Loading

0 comments on commit e00f402

Please sign in to comment.