bcomnes / sublime-standard-format

:sparkles: Runs standard --fix against the javascript in your ST3 window on save or manually.
https://packagecontrol.io/packages/StandardFormat
MIT License
60 stars 21 forks source link

indentation formatting error after several comment lines #71

Closed mesqueeb closed 4 years ago

mesqueeb commented 6 years ago

I have a formatting problem where the there are countless of indentation mistakes after a few lines of comments.

I have deleted many lines for the sake of focussing on just the wrong formatting.

before:

duplicate ({state, getters, commit, dispatch},
    {id = state.selection.selectedId} = {id:state.selection.selectedId})
{
    return new Promise((resolve, reject) => {
        function doRecursively(item, newParentId) {
            // Set up a dupe of the main item & add a node without inserting into the DOM yet.
            let dupeItem = JSON.parse(JSON.stringify(item));
            return dupeItem.id
        }

        dispatch('addItem', {item: mainDupeItem, index, addNextItemAs: 'stop'})
        .then(_ => {
            // One after each other:
                // causes bugs with syncing children_order of mainDupeItem afterwards. I DONT KNOW WHY
            // dispatch('postNewItem', {items: [mainDupeItem]})
            // .then(_ => dispatch('postNewItem', {items: dupeChildren}))
            // In one go:
            dispatch('postNewItem', {items: mainAndAllChildren})
            .then(_ => {
                console.log('finished Duplication of :', id);
                resolve('finished Duplicate', _)
            })
            .catch(error => reject(error));
        });
    });
},

after:

  duplicate ({state, getters, commit, dispatch},
  {id = state.selection.selectedId} = {id: state.selection.selectedId}) {
    return new Promise((resolve, reject) => {
      function doRecursively (item, newParentId) {
      // Set up a dupe of the main item & add a node without inserting into the DOM yet.
        let dupeItem = JSON.parse(JSON.stringify(item))
        return dupeItem.id
      }

      dispatch('addItem', {item: mainDupeItem, index, addNextItemAs: 'stop'})
    .then(_ => {
      // One after each other:
        // causes bugs with syncing children_order of mainDupeItem afterwards. I DONT KNOW WHY
      // dispatch('postNewItem', {items: [mainDupeItem]})
      // .then(_ => dispatch('postNewItem', {items: dupeChildren}))
      // In one go:
  dispatch('postNewItem', {items: mainAndAllChildren})
      .then(_ => {
  console.log('finished Duplication of :', id)
  resolve('finished Duplicate', _)
})
      .catch(error => reject(error))
})
    })
  },

Please see this final part where all indentation gets really messy.

bcomnes commented 6 years ago

Likely an upstream issue with the fix code of the different ESlint rules inside of standard. This plugin is just plumbing around standard's fix flag. What version of standard are you running?

mesqueeb commented 6 years ago

@bcomnes standard --version 10.0.3

mesqueeb commented 6 years ago

@bcomnes Can I check the ESlint rules inside standard to see if anything is set wrong? I'm not sure how to solve this issue. : S

bcomnes commented 4 years ago

Seems to format fine now. Further refactoring could improve the format.

Results:

class Foo {
  duplicate ({ state, getters, commit, dispatch },
    { id = state.selection.selectedId } = { id: state.selection.selectedId }) {
    return new Promise((resolve, reject) => {
      function doRecursively (item, newParentId) {
      // Set up a dupe of the main item & add a node without inserting into the DOM yet.
        const dupeItem = JSON.parse(JSON.stringify(item))
        return dupeItem.id
      }

      dispatch('addItem', { item: mainDupeItem, index, addNextItemAs: 'stop' })
        .then(_ => {
          // One after each other:
        // causes bugs with syncing children_order of mainDupeItem afterwards. I DONT KNOW WHY
          // dispatch('postNewItem', {items: [mainDupeItem]})
          // .then(_ => dispatch('postNewItem', {items: dupeChildren}))
          // In one go:
          dispatch('postNewItem', { items: mainAndAllChildren })
            .then(_ => {
              console.log('finished Duplication of :', id)
              resolve('finished Duplicate', _)
            })
            .catch(error => reject(error))
        })
    })
  }
}