<commit_before>import sublime
import sublime_plugin

class JasmineScaffoldCommand(sublime_plugin.TextCommand):

    # whether tabs are being translated to spaces or not
    # return boolean
	def translatingTabsToSpaces(self):
		return self.view.settings().get('translate_tabs_to_spaces')

	# counts the spacing being used
	# return int
	def spacingSetting(self):
		return self.view.settings().get('tab_size')

	# count the number of whitespace characters at the start of each line
	# return int
	def countLineWhitespace(self, line, type):
		return len(line) - len(line.lstrip(type))

	def buildScaffold(self, lines, spacingCount, spacingType):
		scaffold = []

		for index, line in enumerate(lines):
			currentWs = self.countLineWhitespace(line, spacingType)

			if index < len(lines) - 1:
				nextWs = self.countLineWhitespace(lines[index + 1], spacingType)
			else:
				nextWs = 0

			replacement = 'describe(\'' + line.lstrip(spacingType) + '\', function() {\n\n'
			indented = replacement.rjust(len(replacement) + currentWs, spacingType)

			if currentWs > nextWs:
				replacement = 'it(\'' + line.lstrip(spacingType) + '\', function() {\n\n'
				copy = currentWs
				indented = []

				indented.extend(replacement.rjust(len(replacement) + currentWs, spacingType) + '});'.rjust(3 + currentWs, spacingType) + '\n\n')

				while copy > nextWs:
					copy -= spacingCount
					closeBrackets = '});'.rjust(3 + copy, spacingType) + '\n\n'
					indented.extend(closeBrackets)

			scaffold.extend(indented)

		return scaffold

	# main
	def run(self, edit):
		lines = []

		# create a region from the first sel to the last
		region = sublime.Region(0, self.view.size())
		file = self.view.substr(region)

		# create an array of lines
		for line in file.splitlines():
			lines.append(line)

		if self.translatingTabsToSpaces():
			scaffolded = self.buildScaffold(lines, self.spacingSetting(), ' ')
		else:
			scaffolded = self.buildScaffold(lines, self.spacingSetting(), '\t')

		# replace the whole view with the joined array we've just created<commit_msg>fix issue with tabs, comment functions clearly<commit_after>import sublime
import sublime_plugin

class JasmineScaffoldCommand(sublime_plugin.TextCommand):

    # whether tabs are being translated to spaces or not
    # return [bool]
	def translatingTabsToSpaces(self):
		return self.view.settings().get('translate_tabs_to_spaces')

	# counts the spacing being used
	# return [int]
	def spacingSetting(self):
		return self.view.settings().get('tab_size')

	# count the number of whitespace characters at the start of each line
	# return [int]
	def countLineWhitespace(self, line, type):
		return len(line) - len(line.lstrip(type))

	# param [list] lines read from file in focus
	# param [int] spacingCount tab/space size
	# param [str] spacingType space or tab character
	# param [bool] usingSpaces current user setting, spaces or tabs
	# todo refactor out into smaller chunks
	# return [list] scaffold
	def buildScaffold(self, lines, spacingCount, spacingType, usingSpaces):
		scaffold = []

		for index, line in enumerate(lines):
			currentWhitespace = self.countLineWhitespace(line, spacingType)

			if index < len(lines) - 1:
				nextWhitespace = self.countLineWhitespace(lines[index + 1], spacingType)
			else:
				nextWhitespace = 0

			descRepl = 'describe(\'' + line.lstrip(spacingType) + '\', function() {\n\n'
			indented = descRepl.rjust(len(descRepl) + currentWhitespace, spacingType)

			if currentWhitespace > nextWhitespace:
				itRepl = 'it(\'' + line.lstrip(spacingType) + '\', function() {\n\n'
				copy = currentWhitespace
				indented = []

				indented.append(itRepl.rjust(len(itRepl) + currentWhitespace, spacingType) + '});'.rjust(3 + currentWhitespace, spacingType) + '\n\n')
				while copy > nextWhitespace:
					copy -= spacingCount if usingSpaces else 1
					closeBrackets = '});'.rjust(3 + copy, spacingType) + '\n\n'
					indented.append(closeBrackets)

			scaffold.extend(indented)

		return scaffold

	# main
	def run(self, edit):
		lines = []

		# create a region from the first sel to the last
		region = sublime.Region(0, self.view.size())
		file = self.view.substr(region)

		# create an array of lines
		for line in file.splitlines():
			lines.append(line)

		if self.translatingTabsToSpaces():
			scaffolded = self.buildScaffold(lines, self.spacingSetting(), ' ', True)
		else:
			scaffolded = self.buildScaffold(lines, self.spacingSetting(), '\t', False)	

		# replace the whole view with the joined array we've just created
{'fraction_non_alphanumeric': 0.11788167516064701, 'fraction_numerical': 0.0028805672501661865, 'mean_word_length': 4.158857142857143, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '25764', 'n_tokens_mistral': 1672, 'n_tokens_neox': 1417, 'n_words': 390}