<commit_before>'use babel';

import { createFormattingOptions, createFormattingOptionsFromStylint, format } from 'stylus-supremacy'

import AtomStylusSupremacyView from './atom-stylus-supremacy-view';
import { CompositeDisposable } from 'atom';
import fs from 'fs'
import path from 'path'

function isStylus (textEditor) {
  const { scopes } = textEditor.getRootScopeDescriptor()
  return /.stylus$/.test(scopes[0])
}

function getStylintOptionsFromFile (textEditor) {
  const [ projectPath, filePath ] = atom.project
                                      .relativizePath(textEditor.getPath())
  const pathArray = (path.sep + filePath)
                      .split(path.sep)
                      .slice(0, -1)
  const rulesPath = pathArray.reduce(result => {
    const currentPath = path.join(projectPath, ...result, '.stylintrc')
    if (fs.existsSync(currentPath)) {
      return [...result, '.stylintrc']
    }
    return result.slice(0, -1)
  }, pathArray).join(path.sep)
  if (!rulesPath) {
    atom.notifications.addError('Stylus supremacy: Can\'t find .stylintrc file.')
    throw new Error('Can\'t find .stylintrc file.')
  }
  const rules = JSON.parse(
    fs.readFileSync(path.join(projectPath, rulesPath), 'utf8')
  )
  return createFormattingOptionsFromStylint(rules)
}
function getFormattedStylusText (textEditor) {
  const formattingOptions = getStylintOptionsFromFile(textEditor)
  console.log(formattingOptions);
  const content = textEditor.getText()
  return format(content, formattingOptions)
}

export default {

  atomStylusSupremacyView: null,
  modalPanel: null,
  subscriptions: null,

  config: {
    fixOnSave: {
      type: 'boolean',
      default: false,
      description: 'Let this package fix your stylus file on save.'
    }
  },

  activate(state) {
    this.atomStylusSupremacyView = new AtomStylusSupremacyView(state.atomStylusSupremacyViewState);
    this.modalPanel = atom.workspace.addModalPanel({
      item: this.atomStylusSupremacyView.getElement(),
      visible: true
    });

    // Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
    this.subscriptions = new CompositeDisposable();<commit_msg>edited rulesPath for non-stylintrc<commit_after>'use babel';

import { createFormattingOptions, createFormattingOptionsFromStylint, format } from 'stylus-supremacy'

import AtomStylusSupremacyView from './atom-stylus-supremacy-view';
import { CompositeDisposable } from 'atom';
import fs from 'fs'
import path from 'path'

function isStylus (textEditor) {
  const { scopes } = textEditor.getRootScopeDescriptor()
  return /.stylus$/.test(scopes[0])
}

function getStylintOptionsFromFile (textEditor) {
  const [ projectPath, filePath ] = atom.project
                                      .relativizePath(textEditor.getPath())
  const pathArray = (path.sep + filePath)
                      .split(path.sep)
                      .slice(0, -1)
  const rulesPath = pathArray.reduce(result => {
    const currentPath = path.join(projectPath, ...result, '.stylintrc')
    if (fs.existsSync(currentPath)) {
      return [...result, '.stylintrc']
    }
    return result.slice(0, -1)
  }, pathArray).join(path.sep)
  if (!rulesPath) return
  const rules = JSON.parse(
    fs.readFileSync(path.join(projectPath, rulesPath), 'utf8')
  )
  return createFormattingOptionsFromStylint(rules)
}
function getFormattedStylusText (textEditor) {
  const formattingOptions = getStylintOptionsFromFile(textEditor)
  const content = textEditor.getText()
  return format(content, formattingOptions)
}

export default {

  atomStylusSupremacyView: null,
  modalPanel: null,
  subscriptions: null,

  config: {
    fixOnSave: {
      type: 'boolean',
      default: false,
      description: 'Let this package fix your stylus file on save.'
    }
  },

  activate(state) {
    this.atomStylusSupremacyView = new AtomStylusSupremacyView(state.atomStylusSupremacyViewState);
    this.modalPanel = atom.workspace.addModalPanel({
      item: this.atomStylusSupremacyView.getElement(),
      visible: true
    });

    // Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
    this.subscriptions = new CompositeDisposable();
{'fraction_non_alphanumeric': 0.10763394973921289, 'fraction_numerical': 0.002844950213371266, 'mean_word_length': 3.5958605664488017, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3368891', 'n_tokens_mistral': 1329, 'n_tokens_neox': 1291, 'n_words': 290}