ifc-language-server/node_modules/@stylistic/eslint-plugin/dist/rules/eol-last.js
Ryan Schultz 8afacf268a Implemented a working Language Server Protocol (LSP) for IFC files with:
- Hover provider showing entity information and type
- Go-to-definition (F12) for entity references
- Basic IFC file validation (ISO-10303-21 header check)
- Entity parsing with regex-based detection
- Proper CommonJS module system (avoiding ES module issues)

This replaces the broken baseline from ifc-developer-tools which had:
- Non-functional ES module configuration
- Circular dependency issues
- Parser crashes
- Non-working PositionVisitor

Built on Microsoft's LSP example template for a clean, maintainable foundation.

Next: Add hierarchical entity dependency tree in hover tooltip."
2025-12-07 10:20:07 -06:00

84 lines
2.4 KiB
JavaScript

'use strict';
var utils = require('../utils.js');
require('eslint-visitor-keys');
require('espree');
require('estraverse');
var eolLast = utils.createRule({
name: "eol-last",
package: "js",
meta: {
type: "layout",
docs: {
description: "Require or disallow newline at the end of files"
},
fixable: "whitespace",
schema: [
{
type: "string",
enum: ["always", "never", "unix", "windows"]
}
],
messages: {
missing: "Newline required at end of file but not found.",
unexpected: "Newline not allowed at end of file."
}
},
create(context) {
return {
Program: function checkBadEOF(node) {
const sourceCode = context.sourceCode;
const src = sourceCode.getText();
const lastLine = sourceCode.lines[sourceCode.lines.length - 1];
const location = {
column: lastLine.length,
line: sourceCode.lines.length
};
const LF = "\n";
const CRLF = `\r${LF}`;
const endsWithNewline = src.endsWith(LF);
if (!src.length)
return;
let mode = context.options[0] || "always";
let appendCRLF = false;
if (mode === "unix") {
mode = "always";
}
if (mode === "windows") {
mode = "always";
appendCRLF = true;
}
if (mode === "always" && !endsWithNewline) {
context.report({
node,
loc: location,
messageId: "missing",
fix(fixer) {
return fixer.insertTextAfterRange([0, src.length], appendCRLF ? CRLF : LF);
}
});
} else if (mode === "never" && endsWithNewline) {
const secondLastLine = sourceCode.lines[sourceCode.lines.length - 2];
context.report({
node,
loc: {
start: { line: sourceCode.lines.length - 1, column: secondLastLine.length },
end: { line: sourceCode.lines.length, column: 0 }
},
messageId: "unexpected",
fix(fixer) {
const finalEOLs = /(?:\r?\n)+$/u;
const match = finalEOLs.exec(sourceCode.text);
const start = match.index;
const end = sourceCode.text.length;
return fixer.replaceTextRange([start, end], "");
}
});
}
}
};
}
});
module.exports = eolLast;