question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Intendation suggested by eslint is odd in few cases

See original GitHub issue

What rule do you want to change? The way how eslint calculates intendation. eg. image As you can see eslint suggests to put case in same level as switch though case is inside switch. Or: image ^This is not ok for eslint, but ok for automatic code format in jetbrains (same with first example). Now let’s make small change: image So putting function to next line makes whole block ok, to me both examples look buggy. Does this change cause the rule to produce more or fewer warnings? fewer How will the change be implemented? (New option, new default behavior, etc.)? It could be new option, if for anybody else this is desired bahavior.

eslintrc.js
module.exports = {
    env: {
        'browser': true,
        'es2020': true
    },
    extends: ['eslint:recommended', 'plugin:angular/johnpapa'],
    parserOptions: {
        ecmaVersion: 11,
        sourceType: 'module'
    },
    globals: {
        require: true,
        module: true,
    },
    rules: {
        'angular/module-getter': 0,
        'angular/file-name': [0],
        'angular/controller-as-vm': 0,
        indent: [
            'warn',
            4
        ],
        'linebreak-style': [
            'error',
            'windows'
        ],
        quotes: [
            'error',
            'single'
        ],
        semi: [
            'error',
            'always'
        ]
    },
    parser: 'babel-eslint',
    plugins: [
        'angular'
    ],
};
file with switch case
import servicesModule, {ASSERTION_LABELS} from './app.common.services';
import _ from 'lodash';

servicesModule
    .factory('Field', [
        'Resource', 'Account', '$injector', 'FieldTemplate', '$filter',
        function field(Resource, Account, $injector, FieldTemplate, $filter) {

            const r = Resource.do('fields', {
                methods: {
                    getValue: function () {
                        let l, f;
                        switch (this.template.type) {
                            //case 'ASSERTION':
                            //    if (this.template.options.existing){
                            //
                            //    }
                        case 'RELATION':
                                if (this.template.options.to === 'user') {
                                    const Forms = $injector.get('Forms');
                                    l = Forms.getTeam();
                                    f = (list, id) => _.find(list, el => el.id === id);
                                } else {
                                    l = this.template.options.to === 'account' ? Account : $injector.get('Item');
                                    f = (list, id) => list.get({id: id});
                                }
                                if (this.template.options.direction === 'O2M' || this.template.options.direction === 'M2M') {
                                    return _.map(this.value.value, id => f(l, id));
                                } else {
                                    return f(l, this.value.value);
                                }
                            case 'CHOICE':
                                if (!this.value.value) {
                                    return null;
                                } else {
                                    const val = this.value.value;
                                    return _.find(this.template.options.choices, v => v[0] === val)[0];
                                }
                            case 'INT':
                                return parseInt(this.value.value);
                            case 'BOOLEAN':
                                return !!this.value.value;
                            case 'DECIMAL':
                                if (typeof this.value.value === 'string') {
                                    return parseFloat(this.value.value.replace(',', '.'));
                                }
                                return this.value.value;
                            default:
                                console.log(this.template.type);
                                //TODO znalezienie przyczyny
                                return this.value?.value || '';
                        }
                    },
                    getDisplayValue: function (options) {
                        const n = this.value.value;
                        if (this.template.type === 'CHOICE') {
                            return n ? _.find(this.template.options.choices, v => v[0] === n)[1] : '';
                        } else if (this.template.type === 'ASSERTIONS') {
                            return _.map(n, (d, id) => {
                                const acc = Account.getById(id);
                                // eslint-disable-next-line angular/function-type
                                const assertions = _.filter(ASSERTION_LABELS, (v, k) => d[k]);
                                return acc.getLabel() + ' - ' + assertions.join(', ');
                            }).join('; ');
                        } else if (this.template.type === 'RELATION') {
                            if (this.template.options.direction === 'O2M' || this.template.options.direction === 'M2M') {
                                return _.map(this.getValue(), v => v.getLabel()).join(', ');
                            } else {
                                const v = this.getValue();
                                return v && v.getLabel();
                            }
                        } else if (this.template.type === 'INT') {
                            return n + '';
                        } else if (this.template.type === 'DECIMAL') {
                            return $filter('decimal')(n, options || {});
                        } else if (this.template.type === 'BOOLEAN') {
                            return '<i class="glyphicon glyphicon-' + (n ? 'ok' : 'remove') + '"></i>';
                        } else if (this.template.type === 'DATE') {
                            if (typeof n == 'string') {
                                return n && n.split('T')[0];
                            } else {
                                return n && n.toISOString().split('T')[0];
                            }
                        } else if (this.template.type === 'TEXT' || this.template.type === 'STRING') {
                            return n;
                        } else {
                            return n;
                        }
                    }
                },
                index: true
            });

            Object.defineProperty(r.getResourceClass().prototype, 'template', {
                get: function () {
                    return FieldTemplate.getById(this.template_id);
                }
            });

            r.getByName = (name, item) => _.find(
                r.all(),
                f => {
                    if (item) {
                        return f.template.slug === name && f.item_id === item?.id;
                    }
                    return f.template.slug === name; //&& f.item_id === item?.id
                }
            );

            return r;
        }
    ]);

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
anikethsahacommented, Jul 22, 2020

Thanks for the issue

May be switchcase option can be helpful for you.

0reactions
nzakascommented, Aug 10, 2020

Question is answered, so closing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

indent - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
eslint/eslint - Gitter
it's weird that it would get read even when i specify a config though ... In any case, use --no-eslintrc to disable searching...
Read more >
Cannot fix eslint rule on indenting case statements in switch ...
eslintrc file in my react app. I googled for a solution and saw suggestions to add both switchCase and indentSwitchCase, but my .eslintrc...
Read more >
Setting up efficient workflows with ESLint, Prettier and ...
In any case you can say that all modern IDEs (IntelliJ and VS Code) support ESLint. It is important to note that you...
Read more >
A Bit On ESLint Configuration In A React Project - Medium
The weird part to me is that in some cases you'll see a hefty list ... In most cases, I see recommended used,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found